Permalink
Browse files

fixing arity2 test

  • Loading branch information...
1 parent c718256 commit dbee8c32588083f54857e01b20479229b2f49498 @tenderlove tenderlove committed May 14, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 activesupport/lib/active_support/callbacks.rb
@@ -109,10 +109,10 @@ def call(env)
class Before
def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
@egilburg
egilburg May 14, 2013 Contributor
def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
  if chain_config.key? :terminator
    halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__

    if user_conditions.any?
      halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
    else
      halting(next_callback, user_callback, halted_lambda, filter)
    end
  elsif user_conditions.any?
    conditional(next_callback, user_callback, user_conditions)
  else
    simple(next_callback, user_callback)
  end
end

Also wonder if the class_eval can be done using an exec and plain ruby code?

if chain_config.key?(:terminator) && user_conditions.any?
- halted_lambda = eval "lambda { |result| #{chain_config[:terminator]} }"
+ 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 = eval "lambda { |result| #{chain_config[: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)
@@ -431,7 +431,12 @@ def make_lambda(filter)
l = eval "lambda { |value| #{filter} }"
lambda { |target, value| target.instance_exec(value, &l) }
when ::Proc
- raise ArgumentError if filter.arity > 1
+ if filter.arity > 1
+ return lambda { |target, _, &block|
+ raise ArgumentError unless block
+ target.instance_exec(target, block, &filter)
+ }
+ end
if filter.arity <= 0
lambda { |target, _| target.instance_exec(&filter) }

0 comments on commit dbee8c3

Please sign in to comment.