Module: Mongoid::Observable

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid/observable.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, extended, included

Instance Method Details

#add_observer(object) ⇒ Object

Add an observer to this object. This mimics the standard Ruby observable library.

Example:

address.add_observer(person)



15
16
17
18
# File 'lib/mongoid/observable.rb', line 15

def add_observer(object)
  @observers ||= []
  @observers.push(object)
end

#notify_observers(*args) ⇒ Object

Notify all the objects observing this object of an update. All observers need to respond to the update method in order to handle this.

Example:

document.notify_observers(self)



26
27
28
# File 'lib/mongoid/observable.rb', line 26

def notify_observers(*args)
  @observers.dup.each { |observer| observer.observe(*args) } if @observers
end