aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb27
1 files changed, 11 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 7559e6dce8..f32bb8a0cc 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -291,13 +291,11 @@ module ActiveSupport
if !halted && user_conditions.all? { |c| c.call(target, value) }
user_callback.call(target, value) {
- env = run.call env
- env.value
+ run.call.value
}
-
env
else
- run.call env
+ run.call
end
end
end
@@ -309,11 +307,10 @@ module ActiveSupport
value = env.value
if env.halted
- run.call env
+ run.call
else
user_callback.call(target, value) {
- env = run.call env
- env.value
+ run.call.value
}
env
end
@@ -328,12 +325,11 @@ module ActiveSupport
if user_conditions.all? { |c| c.call(target, value) }
user_callback.call(target, value) {
- env = run.call env
- env.value
+ run.call.value
}
env
else
- run.call env
+ run.call
end
end
end
@@ -342,8 +338,7 @@ module ActiveSupport
def self.simple(callback_sequence, user_callback)
callback_sequence.around do |env, &run|
user_callback.call(env.target, env.value) {
- env = run.call env
- env.value
+ run.call.value
}
env
end
@@ -373,14 +368,14 @@ module ActiveSupport
def filter; @key; end
def raw_filter; @filter; end
- def merge(chain, new_options)
+ def merge_conditional_options(chain, if_option:, unless_option:)
options = {
:if => @if.dup,
:unless => @unless.dup
}
- options[:if].concat Array(new_options.fetch(:unless, []))
- options[:unless].concat Array(new_options.fetch(:if, []))
+ options[:if].concat Array(unless_option)
+ options[:unless].concat Array(if_option)
self.class.build chain, @filter, @kind, options
end
@@ -701,7 +696,7 @@ module ActiveSupport
filter = chain.find {|c| c.matches?(type, filter) }
if filter && options.any?
- new_filter = filter.merge(chain, options)
+ new_filter = filter.merge_conditional_options(chain, if_option: options[:if], unless_option: options[:unless])
chain.insert(chain.index(filter), new_filter)
end