module SwitchConnection::ClassMethods

Public Instance Methods

config() click to toggle source
# File lib/switch_connection.rb, line 13
def config
  @config ||= Config.new
end
configure(&block) click to toggle source
# File lib/switch_connection.rb, line 9
def configure(&block)
  block.call(config)
end
master!(name) click to toggle source
# File lib/switch_connection.rb, line 33
def master!(name)
  ProxyRepository.checkout(name).master!
end
master_all!() click to toggle source
# File lib/switch_connection.rb, line 27
def master_all!
  config.each_key do |name|
    master!(name)
  end
end
slave!(name) click to toggle source
# File lib/switch_connection.rb, line 23
def slave!(name)
  ProxyRepository.checkout(name).slave!
end
slave_all!() click to toggle source
# File lib/switch_connection.rb, line 17
def slave_all!
  config.each_key do |name|
    slave!(name)
  end
end
with_master(*names, &block) click to toggle source
# File lib/switch_connection.rb, line 45
def with_master(*names, &block)
  with_mode(:master, *names, &block)
end
with_master_all(&block) click to toggle source
# File lib/switch_connection.rb, line 49
def with_master_all(&block)
  with_master(*config.keys, &block)
end
with_mode(mode, *names, &block) click to toggle source
# File lib/switch_connection.rb, line 53
def with_mode(mode, *names, &block)
  names.reverse.inject(block) do |func, name|
    lambda do
      ProxyRepository.checkout(name).with_mode(mode, &func)
    end
  end.call
end
with_slave(*names, &block) click to toggle source
# File lib/switch_connection.rb, line 37
def with_slave(*names, &block)
  with_mode(:slave, *names, &block)
end
with_slave_all(&block) click to toggle source
# File lib/switch_connection.rb, line 41
def with_slave_all(&block)
  with_slave(*config.keys, &block)
end