make_lambda(filter)
private
Filters support:
Symbols:: A method to call.
Strings:: Some content to evaluate.
Procs:: A proc to call with the object.
Objects:: An object with a <tt>before_foo</tt> method on it to call.
All of these objects are converted into a lambda and handled the same after
this point.
# File activesupport/lib/active_support/callbacks.rb, line 429
def make_lambda(filter)
case filter
when Symbol
lambda { |target, _, &blk| target.send filter, &blk }
when String
l = eval "lambda { |value| #{filter} }"
lambda { |target, value| target.instance_exec(value, &l) }
when Conditionals::Value then filter
when ::Proc
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) }
else
lambda { |target, _| target.instance_exec(target, &filter) }
end
else
scopes = Array(chain_config[:scope])
method_to_call = scopes.map{ |s| public_send(s) }.join("_")
lambda { |target, _, &blk|
filter.public_send method_to_call, target, &blk
}
end
end