Methods
Instance Public methods
Instantiate the global ActiveRecord observers
Source: show
# File rails/activerecord/lib/active_record/observer.rb, line 34 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 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
Gets the current observers.
Source: show
# File rails/activerecord/lib/active_record/observer.rb, line 29 def observers @observers ||= [] end
Activates the observers assigned. Examples:
# Calls PersonObserver.instance ActiveRecord::Base.observers = :person_observer # Calls Cacher.instance and GarbageCollector.instance ActiveRecord::Base.observers = :cacher, :garbage_collector # Same as above, just using explicit class references ActiveRecord::Base.observers = Cacher, GarbageCollector
Note: Setting this does not instantiate the observers yet. instantiate_observers is called during startup, and before each development request.
Source: show
# File rails/activerecord/lib/active_record/observer.rb, line 24 def observers=(*observers) @observers = observers.flatten end
Instance Protected methods
Notify observers when the observed class is subclassed.
Source: show
# File rails/activerecord/lib/active_record/observer.rb, line 49 def inherited(subclass) super changed notify_observers :observed_class_inherited, subclass end