lib/switch_point/model.rb in switch_point-0.1.0 vs lib/switch_point/model.rb in switch_point-0.2.0

- old
+ new

@@ -3,40 +3,43 @@ module SwitchPoint module Model def self.included(model) model.singleton_class.class_eval do include ClassMethods - prepend ConnectionHook + alias_method_chain :connection, :switch_point end end - module ConnectionHook - def connection + module ClassMethods + def connection_with_switch_point if @switch_point_name switch_point_proxy.connection else - super + connection_without_switch_point end end - end - module ClassMethods def with_readonly(&block) switch_point_proxy.with_readonly(&block) end def with_writable(&block) switch_point_proxy.with_writable(&block) end - private - def use_switch_point(name) + assert_existing_switch_point!(name) @switch_point_name = name end + private + + def assert_existing_switch_point!(name) + SwitchPoint.config.fetch(name) + end + def switch_point_proxy - @switch_point_proxy ||= ProxyRepository.find(@switch_point_name) + ProxyRepository.checkout(@switch_point_name) end end end end