Skip to content
Browse files

pass the run block as a normal variable to the rest of the callbacks

  • Loading branch information...
1 parent 9b52026 commit d4dcd6e41f4a7c202270e7d510434351ce333ebc @tenderlove tenderlove committed May 9, 2013
Showing with 12 additions and 12 deletions.
  1. +12 −12 activesupport/lib/active_support/callbacks.rb
View
24 activesupport/lib/active_support/callbacks.rb
@@ -176,45 +176,45 @@ def apply(next_callback)
case @kind
when :before
halted_lambda = eval "lambda { |result| #{chain.config[:terminator]} }"
- lambda { |target, halted, value, &block|
+ lambda { |target, halted, value, run_block|
if !halted && user_conditions.all? { |c| c.call(target, value) }
result = user_callback.call target, value
halted = halted_lambda.call result
if halted
target.send :halted_callback_hook, @raw_filter.inspect
end
end
- next_callback.call target, halted, value, &block
+ next_callback.call target, halted, value, run_block
}
when :after
if chain.config[:skip_after_callbacks_if_terminated]
- lambda { |target, halted, value, &block|
- target, halted, value = next_callback.call target, halted, value, &block
+ lambda { |target, halted, value, run_block|
+ target, halted, value = next_callback.call target, halted, value, run_block
if !halted && user_conditions.all? { |c| c.call(target, value) }
user_callback.call target, value
end
[target, halted, value]
}
else
- lambda { |target, halted, value, &block|
- target, halted, value = next_callback.call target, halted, value, &block
+ lambda { |target, halted, value, run_block|
+ target, halted, value = next_callback.call target, halted, value, run_block
if user_conditions.all? { |c| c.call(target, value) }
user_callback.call target, value
end
[target, halted, value]
}
end
when :around
- lambda { |target, halted, value, &block|
+ lambda { |target, halted, value, run_block|
if !halted && user_conditions.all? { |c| c.call(target, value) }
retval = nil
user_callback.call(target, value) {
- retval = next_callback.call(target, halted, value, &block)
+ retval = next_callback.call(target, halted, value, run_block)
retval.last
}
retval
else
- next_callback.call target, halted, value, &block
+ next_callback.call target, halted, value, run_block
end
}
end
@@ -334,8 +334,8 @@ def initialize(name, config)
end
def compile
- callbacks = lambda { |target,halted,value,&block|
- value = !halted && (!block || block.call)
+ callbacks = lambda { |target, halted, value, run_block|
+ value = run_block.call if run_block && !halted
[target, halted, value]
}
reverse_each do |callback|
@@ -381,7 +381,7 @@ def __define_callbacks(kind, object) #:nodoc:
str = object.send("_#{kind}_callbacks").compile
class_eval do
define_method(name) do |&block|
- str.call(self, false, nil, &block)[2]
+ str.call(self, false, nil, block)[2]
end
protected name
end

0 comments on commit d4dcd6e

Please sign in to comment.
Something went wrong with that request. Please try again.