# File lib/active_model/observing.rb, line 42
42: def add_observer(observer)
43: unless observer.respond_to? :update
44: raise ArgumentError, "observer needs to respond to `update'"
45: end
46: @observer_instances ||= []
47: @observer_instances << observer
48: end
# File lib/active_model/observing.rb, line 58
58: def count_observers
59: @observer_instances.size
60: end
Instantiate the global Active Record observers.
# File lib/active_model/observing.rb, line 38
38: def instantiate_observers
39: observers.each { |o| instantiate_observer(o) }
40: end
# File lib/active_model/observing.rb, line 50
50: def notify_observers(*arg)
51: if defined? @observer_instances
52: for observer in @observer_instances
53: observer.update(*arg)
54: end
55: end
56: end
Gets the current observers.
# File lib/active_model/observing.rb, line 33
33: def observers
34: @observers ||= []
35: 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 lib/active_model/observing.rb, line 28
28: def observers=(*values)
29: @observers = values.flatten
30: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.