Files

Class/Module Index [+]

Quicksearch

ActiveRecord::Observing::ClassMethods

Public Instance Methods

instantiate_observers() click to toggle source

Instantiate the global Active Record observers.

# File 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() click to toggle source

Gets the current observers.

# File lib/active_record/observer.rb, line 29
def observers
  @observers ||= []
end
observers=(*observers) click to toggle source

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 lib/active_record/observer.rb, line 24
def observers=(*observers)
  @observers = observers.flatten
end

Protected Instance Methods

inherited(subclass) click to toggle source

Notify observers when the observed class is subclassed.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.