lib/switch_point/model.rb in switch_point-0.6.0 vs lib/switch_point/model.rb in switch_point-0.7.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'switch_point/error'
require 'switch_point/proxy_repository'
module SwitchPoint
module Model
def self.included(model)
@@ -38,19 +39,19 @@
def with_readonly(&block)
if switch_point_proxy
switch_point_proxy.with_readonly(&block)
else
- block.call
+ raise UnconfiguredError.new("#{name} isn't configured to use switch_point")
end
end
def with_writable(&block)
if switch_point_proxy
switch_point_proxy.with_writable(&block)
else
- block.call
+ raise UnconfiguredError.new("#{name} isn't configured to use switch_point")
end
end
def use_switch_point(name)
assert_existing_switch_point!(name)
@@ -67,15 +68,15 @@
end
end
def transaction_with(*models, &block)
unless can_transaction_with?(*models)
- raise RuntimeError.new("switch_point's model names must be consistent")
+ raise Error.new("switch_point's model names must be consistent")
end
with_writable do
- self.transaction(&block)
+ transaction(&block)
end
end
private
@@ -88,11 +89,9 @@
if model.instance_variable_defined?(:@switch_point_name)
SwitchPoint.config.model_name(
model.instance_variable_get(:@switch_point_name),
:writable
)
- else
- nil
end
end
writable_switch_points.uniq.size == 1
end