Module | ActiveRecord::Observing::ClassMethods |
In: |
vendor/rails/activerecord/lib/active_record/observer.rb
|
Instantiate the global ActiveRecord observers
# File vendor/rails/activerecord/lib/active_record/observer.rb, line 34 34: def instantiate_observers 35: return if @observers.blank? 36: @observers.each do |observer| 37: if observer.respond_to?(:to_sym) # Symbol or String 38: observer.to_s.camelize.constantize.instance 39: elsif observer.respond_to?(:instance) 40: observer.instance 41: else 42: 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" 43: end 44: end 45: 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.
# File vendor/rails/activerecord/lib/active_record/observer.rb, line 24 24: def observers=(*observers) 25: @observers = observers.flatten 26: end