Module: SwitchPoint::ClassMethods

Included in:
SwitchPoint
Defined in:
lib/switch_point.rb

Instance Method Summary collapse

Instance Method Details

#configObject



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

def config
  @config ||= Config.new
end

#configure(&block) ⇒ Object



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

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

#readonly!(name) ⇒ Object



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

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

#readonly_all!Object



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

def readonly_all!
  config.each_key do |name|
    readonly!(name)
  end
end

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



53
54
55
56
57
58
59
# File 'lib/switch_point.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_readonly(*names, &block) ⇒ Object



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

def with_readonly(*names, &block)
  with_mode(:readonly, *names, &block)
end

#with_readonly_all(&block) ⇒ Object



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

def with_readonly_all(&block)
  with_readonly(*config.keys, &block)
end

#with_writable(*names, &block) ⇒ Object



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

def with_writable(*names, &block)
  with_mode(:writable, *names, &block)
end

#with_writable_all(&block) ⇒ Object



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

def with_writable_all(&block)
  with_writable(*config.keys, &block)
end

#writable!(name) ⇒ Object



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

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

#writable_all!Object



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

def writable_all!
  config.each_key do |name|
    writable!(name)
  end
end