From 833ea903a9591b3b7d805981c0d0dbadf53cb58d Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Thu, 15 Dec 2016 19:23:10 +1030 Subject: Support double-yield inside an around callback It's questionable whether this is a good thing -- it forces any later/ inner callback to handle multiple invocations, along with the actual wrapped action. But it worked prior to 871ca21f6a1d65c0ec78cb5a9641411e2210460b, so we shouldn't break it unintentionally. --- activesupport/lib/active_support/callbacks.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index af8ddb176f..e6c79f2a38 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -109,16 +109,22 @@ module ActiveSupport invoke_sequence = Proc.new do skipped = nil while true - current, next_sequence = next_sequence, next_sequence.nested + current = next_sequence current.invoke_before(env) if current.final? env.value = !env.halted && (!block_given? || yield) elsif current.skip?(env) (skipped ||= []) << current + next_sequence = next_sequence.nested next else - target, block, method, *arguments = current.expand_call_template(env, invoke_sequence) - target.send(method, *arguments, &block) + next_sequence = next_sequence.nested + begin + target, block, method, *arguments = current.expand_call_template(env, invoke_sequence) + target.send(method, *arguments, &block) + ensure + next_sequence = current + end end current.invoke_after(env) skipped.pop.invoke_after(env) while skipped && skipped.first -- cgit v1.2.3