Module: SwitchConnection::ClassMethods

Included in:
SwitchConnection
Defined in:
lib/switch_connection.rb

Instance Method Summary collapse

Instance Method Details

#configObject



13
14
15
# File 'lib/switch_connection.rb', line 13

def config
  @config ||= Config.new
end

#configure(&block) ⇒ Object



9
10
11
# File 'lib/switch_connection.rb', line 9

def configure(&block)
  block.call(config)
end

#master!(name) ⇒ Object



33
34
35
# File 'lib/switch_connection.rb', line 33

def master!(name)
  ProxyRepository.checkout(name).master!
end

#master_all!Object



27
28
29
30
31
# File 'lib/switch_connection.rb', line 27

def master_all!
  config.each_key do |name|
    master!(name)
  end
end

#slave!(name) ⇒ Object



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

def slave!(name)
  ProxyRepository.checkout(name).slave!
end

#slave_all!Object



17
18
19
20
21
# File 'lib/switch_connection.rb', line 17

def slave_all!
  config.each_key do |name|
    slave!(name)
  end
end

#with_master(*names, &block) ⇒ Object



45
46
47
# File 'lib/switch_connection.rb', line 45

def with_master(*names, &block)
  with_mode(:master, *names, &block)
end

#with_master_all(&block) ⇒ Object



49
50
51
# File 'lib/switch_connection.rb', line 49

def with_master_all(&block)
  with_master(*config.keys, &block)
end

#with_mode(mode, *names, &block) ⇒ Object



53
54
55
56
57
58
59
# 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) ⇒ Object



37
38
39
# File 'lib/switch_connection.rb', line 37

def with_slave(*names, &block)
  with_mode(:slave, *names, &block)
end

#with_slave_all(&block) ⇒ Object



41
42
43
# File 'lib/switch_connection.rb', line 41

def with_slave_all(&block)
  with_slave(*config.keys, &block)
end