module DbVcs::Utils

Public Class Methods

current_branch() click to toggle source

@return [String] current branch name

# File lib/db_vcs/utils.rb, line 7
def current_branch
  `git rev-parse --abbrev-ref HEAD`.chomp
end
db_name(environment, branch) click to toggle source

Generate db name, based on branch name and environment. @param environment [String] application’s environment name. E.g. “development”, “test” @param branch [String] @return [String]

# File lib/db_vcs/utils.rb, line 20
def db_name(environment, branch)
  [DbVcs.config.db_basename, environment, branch].map do |str|
    normalize_db_part(str)
  end.join("_")
end
git_branches() click to toggle source

@return [Array<String>] array of local branches names

# File lib/db_vcs/utils.rb, line 12
def git_branches
  `git for-each-ref refs/heads --format='%(refname:short)'`.scan(/[[:graph:]]+/)
end
normalize_db_part(str) click to toggle source

Removes special characters from string that is used as a part of database name @param str [String] @return [String]

# File lib/db_vcs/utils.rb, line 29
def normalize_db_part(str)
  str.gsub(/[\W]/, "_")
end
resolve_exec_path(exec, fallback_exec: nil) click to toggle source

@param exec [String] a name of executable @param fallback_exec [String] a name of executable to fallback to if exec was not resolved @return [String] path to executable

# File lib/db_vcs/utils.rb, line 36
def resolve_exec_path(exec, fallback_exec: nil)
  path = `which #{exec}`.chomp
  return resolve_exec_path(fallback_exec) if fallback_exec && path.empty?

  path.empty? ? exec : path
end