Methods
I
O
Instance Public methods
instantiate_observers()

Instantiate the global ActiveRecord observers

# 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
observers()

Gets the current observers.

# File rails/activerecord/lib/active_record/observer.rb, line 29
def observers
  @observers ||= []
end
observers=(*observers)

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 rails/activerecord/lib/active_record/observer.rb, line 24
def observers=(*observers)
  @observers = observers.flatten
end
Instance Protected methods
inherited(subclass)

Notify observers when the observed class is subclassed.

# File rails/activerecord/lib/active_record/observer.rb, line 49
def inherited(subclass)
  super
  changed
  notify_observers :observed_class_inherited, subclass
end