aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-14 16:03:09 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-14 16:03:09 -0700
commitba552764344bc0a3c25b8576ec11f127ceaa16da (patch)
treee78fb72f5ca735e1e4c0956d79960761fff4f942 /activesupport
parent4c628e48a56920877948bd9d69d3e3caa41b5da8 (diff)
downloadrails-ba552764344bc0a3c25b8576ec11f127ceaa16da.tar.gz
rails-ba552764344bc0a3c25b8576ec11f127ceaa16da.tar.bz2
rails-ba552764344bc0a3c25b8576ec11f127ceaa16da.zip
deprecating string based terminators
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb15
-rw-r--r--activesupport/test/callbacks_test.rb2
2 files changed, 12 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 5b8a300528..429e4f60a4 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -108,11 +108,11 @@ module ActiveSupport
class Before
def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
+ halted_lambda = chain_config[:terminator]
+
if chain_config.key?(:terminator) && user_conditions.any?
- halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__
halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
elsif chain_config.key? :terminator
- halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__
halting(next_callback, user_callback, halted_lambda, filter)
elsif user_conditions.any?
conditional(next_callback, user_callback, user_conditions)
@@ -131,7 +131,7 @@ module ActiveSupport
if !halted && user_conditions.all? { |c| c.call(target, value) }
result = user_callback.call target, value
- env.halted = target.instance_exec result, &halted_lambda
+ env.halted = halted_lambda.call(target, result)
if env.halted
target.send :halted_callback_hook, filter
end
@@ -148,7 +148,7 @@ module ActiveSupport
if !halted
result = user_callback.call target, value
- env.halted = target.instance_exec result, &halted_lambda
+ env.halted = halted_lambda.call(target, result)
if env.halted
target.send :halted_callback_hook, filter
end
@@ -752,6 +752,13 @@ module ActiveSupport
# would call <tt>Audit#save</tt>.
def define_callbacks(*callbacks)
config = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
+ if config.key?(:terminator) && String === config[:terminator]
+ ActiveSupport::Deprecation.warn "String based terminators are deprecated, please use a lambda"
+ value = config[:terminator]
+ l = class_eval "lambda { |result| #{value} }", __FILE__, __LINE__
+ config[:terminator] = lambda { |target, result| target.instance_exec(result, &l) }
+ end
+
callbacks.each do |callback|
class_attribute "_#{callback}_callbacks"
set_callbacks callback, CallbackChain.new(callback, config)
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 86057f7cbb..5fce1eeafc 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -525,7 +525,7 @@ module CallbacksTest
class CallbackTerminator
include ActiveSupport::Callbacks
- define_callbacks :save, :terminator => "result == :halt"
+ define_callbacks :save, :terminator => ->(_,result) { result == :halt }
set_callback :save, :before, :first
set_callback :save, :before, :second