From 10bac29b330ddda69102d43b77a1e7dba8741c45 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Wed, 22 Feb 2012 17:43:13 +0200 Subject: [PATCH] AS::Callbacks: deprecate rescuable option --- .../action_dispatch/middleware/callbacks.rb | 12 ++++++--- activesupport/CHANGELOG.md | 2 ++ activesupport/lib/active_support/callbacks.rb | 27 +------------------ activesupport/test/callbacks_test.rb | 9 +------ 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index 8c0f4052ec9ae..338b116940a9a 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -5,7 +5,7 @@ module ActionDispatch class Callbacks include ActiveSupport::Callbacks - define_callbacks :call, :rescuable => true + define_callbacks :call class << self delegate :to_prepare, :to_cleanup, :to => "ActionDispatch::Reloader" @@ -24,9 +24,15 @@ def initialize(app) end def call(env) - run_callbacks :call do - @app.call(env) + error = nil + result = run_callbacks :call do + begin + @app.call(env) + rescue => error + end end + raise error if error + result end end end diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 29109ea64d6ff..3ec81e05d6d36 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* AS::Callbacks: deprecate `:rescuable` option. *Bogdan Gusiev* + * Adds Integer#ordinal to get the ordinal suffix string of an integer. *Tim Gildea* * AS::Callbacks: `:per_key` option is no longer supported diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 6de49409e5e32..6e36edee4f836 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -307,7 +307,6 @@ def initialize(name, config) @name = name @config = { :terminator => "false", - :rescuable => false, :scope => [ :kind ] }.merge(config) end @@ -317,35 +316,16 @@ def compile method << "value = nil" method << "halted = false" - callbacks = yielding + callbacks = "value = yield if block_given? && !halted" reverse_each do |callback| callbacks = callback.apply(callbacks) end method << callbacks - method << "raise rescued_error if rescued_error" if config[:rescuable] method << "halted ? false : (block_given? ? value : true)" method.flatten.compact.join("\n") end - # Returns part of method that evaluates the callback block - def yielding - method = [] - if config[:rescuable] - method << "rescued_error = nil" - method << "begin" - end - - method << "value = yield if block_given? && !halted" - - if config[:rescuable] - method << "rescue Exception => e" - method << "rescued_error = e" - method << "end" - end - method.join("\n") - end - end module ClassMethods @@ -508,11 +488,6 @@ def reset_callbacks(symbol) # if callback chain was terminated or not. # Option makes sence only when :terminator option is specified. # - # * :rescuable - By default, after filters are not executed if - # the given block or a before filter raises an error. By setting this option - # to true exception raised by given block is stored and after - # executing all the after callbacks the stored exception is raised. - # # * :scope - Indicates which methods should be executed when an object # is used as a callback. # diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 3c995e0793783..25688a9da5d6b 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -3,7 +3,7 @@ module CallbacksTest class Phone include ActiveSupport::Callbacks - define_callbacks :save, :rescuable => true + define_callbacks :save set_callback :save, :before, :before_save1 set_callback :save, :after, :after_save1 @@ -439,13 +439,6 @@ def test_skip_person end class CallbacksTest < ActiveSupport::TestCase - def test_save_phone - phone = Phone.new - assert_raise RuntimeError do - phone.save - end - assert_equal [:before, :after], phone.history - end def test_save_person person = Person.new