1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplify CallbackTemplate#expand

This commit is contained in:
Vinicius Stock 2019-12-14 13:56:06 -05:00 committed by Vinicius Stock
parent 165c5e5668
commit 6e47695370
No known key found for this signature in database
GPG key ID: 1A3EC85374C0969A

View file

@ -129,7 +129,7 @@ module ActiveSupport
end end
end end
current.invoke_after(env) current.invoke_after(env)
skipped.pop.invoke_after(env) while skipped && skipped.first skipped.pop.invoke_after(env) while skipped&.first
break env.value break env.value
end end
end end
@ -401,21 +401,17 @@ module ActiveSupport
# The actual invocation is left up to the caller to minimize # The actual invocation is left up to the caller to minimize
# call stack pollution. # call stack pollution.
def expand(target, value, block) def expand(target, value, block)
result = @arguments.map { |arg| expanded = [@override_target || target, @override_block || block, @method_name]
@arguments.each do |arg|
case arg case arg
when :value; value when :value then expanded << value
when :target; target when :target then expanded << target
when :block; block || raise(ArgumentError) when :block then expanded << (block || raise(ArgumentError))
end
end end
}
result.unshift @method_name expanded
result.unshift @override_block || block
result.unshift @override_target || target
# target, block, method, *arguments = result
# target.send(method, *arguments, &block)
result
end end
# Return a lambda that will make this call when given the input # Return a lambda that will make this call when given the input