# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/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
# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/lib/active_model/observing.rb, line 58 def count_observers @observer_instances.size end
Instantiate the global Active Record observers.
# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/lib/active_model/observing.rb, line 38 def instantiate_observers observers.each { |o| instantiate_observer(o) } end
# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/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
Gets the current observers.
# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/lib/active_model/observing.rb, line 33 def observers @observers ||= [] 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 D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/lib/active_model/observing.rb, line 28 def observers=(*values) @observers = values.flatten end
Notify observers when the observed class is subclassed.
# File D:/Develope/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activemodel-3.0.9/lib/active_model/observing.rb, line 75 def inherited(subclass) super notify_observers :observed_class_inherited, subclass end
Generated with the Darkfish Rdoc Generator 2.