Module: SwitchPoint::Model::ClassMethods
- Defined in:
- lib/switch_point/model.rb
Instance Method Summary collapse
- #switch_point_proxy ⇒ Object
- #transaction_with(*models, &block) ⇒ Object
- #use_switch_point(name) ⇒ Object
- #with_readonly(&block) ⇒ Object
- #with_writable(&block) ⇒ Object
Instance Method Details
#switch_point_proxy ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/switch_point/model.rb', line 48 def switch_point_proxy if defined?(@switch_point_name) ProxyRepository.checkout(@switch_point_name) elsif self == ActiveRecord::Base nil else superclass.switch_point_proxy end end |
#transaction_with(*models, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/switch_point/model.rb', line 58 def transaction_with(*models, &block) unless can_transaction_with?(*models) raise Error.new("switch_point's model names must be consistent") end with_writable do transaction(&block) end end |
#use_switch_point(name) ⇒ Object
43 44 45 46 |
# File 'lib/switch_point/model.rb', line 43 def use_switch_point(name) assert_existing_switch_point!(name) @switch_point_name = name end |
#with_readonly(&block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/switch_point/model.rb', line 27 def with_readonly(&block) if switch_point_proxy switch_point_proxy.with_readonly(&block) else raise UnconfiguredError.new("#{name} isn't configured to use switch_point") end end |
#with_writable(&block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/switch_point/model.rb', line 35 def with_writable(&block) if switch_point_proxy switch_point_proxy.with_writable(&block) else raise UnconfiguredError.new("#{name} isn't configured to use switch_point") end end |