Module: DbVcs::Utils
- Defined in:
- lib/db_vcs/utils.rb
Class Method Summary collapse
-
.current_branch ⇒ String
Current branch name.
-
.db_name(environment, branch) ⇒ String
Generate db name, based on branch name and environment.
-
.git_branches ⇒ Array<String>
Array of local branches names.
-
.normalize_db_part(str) ⇒ String
Removes special characters from string that is used as a part of database name.
-
.resolve_exec_path(exec, fallback_exec: nil) ⇒ String
Path to executable.
Class Method Details
.current_branch ⇒ String
Returns current branch name.
7 8 9 |
# File 'lib/db_vcs/utils.rb', line 7 def current_branch `git rev-parse --abbrev-ref HEAD`.chomp end |
.db_name(environment, branch) ⇒ String
Generate db name, based on branch name and environment.
20 21 22 23 24 |
# 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 ⇒ Array<String>
Returns array of local branches names.
12 13 14 |
# 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) ⇒ String
Removes special characters from string that is used as a part of database name
29 30 31 |
# File 'lib/db_vcs/utils.rb', line 29 def normalize_db_part(str) str.gsub(/[\W]/, "_") end |
.resolve_exec_path(exec, fallback_exec: nil) ⇒ String
Returns path to executable.
36 37 38 39 40 41 |
# 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 |