lib/active_support/rescuable.rb in activesupport-2.3.18 vs lib/active_support/rescuable.rb in activesupport-3.0.0.beta

- old
+ new

@@ -1,13 +1,18 @@ +require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/proc' +require 'active_support/core_ext/string/inflections' +require 'active_support/core_ext/array/extract_options' + module ActiveSupport # Rescuable module adds support for easier exception handling. module Rescuable - def self.included(base) # :nodoc: - base.class_inheritable_accessor :rescue_handlers - base.rescue_handlers = [] + extend Concern - base.extend(ClassMethods) + included do + class_attribute :rescue_handlers + self.rescue_handlers = [] end module ClassMethods # Rescue exceptions raised in controller actions. # @@ -60,11 +65,11 @@ else raise ArgumentError, "#{klass} is neither an Exception nor a String" end # put the new handler at the end because the list is read in reverse - rescue_handlers << [key, options[:with]] + self.rescue_handlers += [[key, options[:with]]] end end end # Tries to rescue the exception by looking up and calling a registered handler. @@ -76,10 +81,10 @@ end def handler_for_rescue(exception) # We go from right to left because pairs are pushed onto rescue_handlers # as rescue_from declarations are found. - _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler| + _, rescuer = self.class.rescue_handlers.reverse.detect do |klass_name, handler| # The purpose of allowing strings in rescue_from is to support the # declaration of handler associations for exception classes whose # definition is yet unknown. # # Since this loop needs the constants it would be inconsistent to