Class Index [+]

Quicksearch

ActiveModel::Observing::ClassMethods

Public Instance Methods

add_observer(observer) click to toggle source

Add a new observer to the pool. The new observer needs to respond to ‘update’, otherwise it raises an ArgumentError exception.

    # File lib/active_model/observing.rb, line 65
65:       def add_observer(observer)
66:         unless observer.respond_to? :update
67:           raise ArgumentError, "observer needs to respond to `update'"
68:         end
69:         observer_instances << observer
70:       end
count_observers() click to toggle source

Total number of observers.

    # File lib/active_model/observing.rb, line 78
78:       def count_observers
79:         observer_instances.size
80:       end
instantiate_observers() click to toggle source

Instantiate the global observers.

    # File lib/active_model/observing.rb, line 58
58:       def instantiate_observers
59:         observers.each { |o| instantiate_observer(o) }
60:       end
notify_observers(*arg) click to toggle source

Notify list of observers of a change.

    # File lib/active_model/observing.rb, line 73
73:       def notify_observers(*arg)
74:         observer_instances.each { |observer| observer.update(*arg) }
75:       end
observer_instances() click to toggle source

Gets the current observer instances.

    # File lib/active_model/observing.rb, line 53
53:       def observer_instances
54:         @observer_instances ||= []
55:       end
observers() click to toggle source

Gets an array of observers observing this model. The array also provides enable and disable methods that allow you to selectively enable and disable observers. (see ActiveModel::ObserverArray.enable and ActiveModel::ObserverArray.disable for more on this)

    # File lib/active_model/observing.rb, line 48
48:       def observers
49:         @observers ||= ObserverArray.new(self)
50:       end
observers=(*values) click to toggle source

Active Model Observers Activation

Activates the observers assigned. Examples:

  class ORM
    include ActiveModel::Observing
  end

  # Calls PersonObserver.instance
  ORM.observers = :person_observer

  # Calls Cacher.instance and GarbageCollector.instance
  ORM.observers = :cacher, :garbage_collector

  # Same as above, just using explicit class references
  ORM.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 39
39:       def observers=(*values)
40:         observers.replace(values.flatten)
41:       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 99
 99:         def inherited(subclass)
100:           super
101:           notify_observers :observed_class_inherited, subclass
102:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.