Class/Module Index [+]

Quicksearch

ActiveModel::Observing::ClassMethods

Public Instance Methods

add_observer(observer) click to toggle source
# File lib/active_model/observing.rb, line 42
def add_observer(observer)
  unless observer.respond_to? :update
    raise ArgumentError, "observer needs to respond to `update'"
  end
  @observer_instances ||= []
  @observer_instances << observer
end
count_observers() click to toggle source
# File lib/active_model/observing.rb, line 58
def count_observers
  @observer_instances.size
end
instantiate_observers() click to toggle source

Instantiate the global Active Record observers.

# File lib/active_model/observing.rb, line 38
def instantiate_observers
  observers.each { |o| instantiate_observer(o) }
end
notify_observers(*arg) click to toggle source
# File lib/active_model/observing.rb, line 50
def notify_observers(*arg)
  if defined? @observer_instances
    for observer in @observer_instances
      observer.update(*arg)
    end
  end
end
observers() click to toggle source

Gets the current observers.

# File lib/active_model/observing.rb, line 33
def observers
  @observers ||= []
end
observers=(*values) click to toggle source

Active Model Observers Activation

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_model/observing.rb, line 28
def observers=(*values)
  @observers = values.flatten
end

Protected Instance Methods

inherited(subclass) click to toggle source

Notify observers when the observed class is subclassed.

# File lib/active_model/observing.rb, line 75
def inherited(subclass)
  super
  notify_observers :observed_class_inherited, subclass
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.