diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 2b0728f..b9606a8 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -34,16 +34,23 @@ module ActiveRecord def instantiate_observers return if @observers.blank? @observers.each do |observer| - if observer.respond_to?(:to_sym) # Symbol or String - observer.to_s.camelize.constantize.instance - elsif observer.respond_to?(:instance) - observer.instance - else + unless instantiate_observer(observer) raise ArgumentError, "#{observer} must be a lowercase, underscored class name (or an instance of the class itself) responding to the instance method. Example: Person.observers = :big_brother # calls BigBrother.instance" end end end + def instantiate_observer(observer) + if observer.respond_to?(:to_sym) # Symbol or String + observer.to_s.camelize.constantize.instance + elsif observer.respond_to?(:instance) + observer.instance + end + rescue Exception => e + logger.warn("Couldn't instantiate observer #{observer.inspect}: #{e.message}") + true + end + protected # Notify observers when the observed class is subclassed. def inherited(subclass)