Module: BranchDb::TaskHelper

Defined in:
lib/branch_db/task_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_branchObject



7
8
9
# File 'lib/branch_db/task_helper.rb', line 7

def current_branch
  BranchDb::current_repo_branch(true)
end

#each_local_configObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/branch_db/task_helper.rb', line 27

def each_local_config
  ActiveRecord::Base.configurations.each do |rails_env, config|
    next unless config['database']
    case per_branch = config['per_branch']
    when true
#        when Hash
    else
      next
    end
    local_database?(config) do
      yield rails_env, config
    end
  end
end

#each_local_database(*args) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/branch_db/task_helper.rb', line 42

def each_local_database(*args)
  options = args.last.kind_of?(Hash) ? args.pop : {}
  options = options.reverse_merge(environment_options)
  branch = args[0] || target_branch
  each_local_config do |rails_env, config|
    yield BranchDb::Switcher.create(rails_env, config, branch, options)
  end
end

#environment_optionsObject



11
12
13
14
15
16
17
# File 'lib/branch_db/task_helper.rb', line 11

def environment_options
  returning options = {} do
    [:overwrite, :verbose].each do |opt|
      options[opt] = (ENV[opt.to_s.upcase] =~ /\A(true|1)\Z/i) == 0
    end
  end
end

#originating_branchObject



23
24
25
# File 'lib/branch_db/task_helper.rb', line 23

def originating_branch
  ENV['ORIG_BRANCH'] || 'master' ### TODO determine originating branch
end

#target_branchObject



19
20
21
# File 'lib/branch_db/task_helper.rb', line 19

def target_branch
  ENV['BRANCH'] || current_branch
end