Sha256: 33a376384af1d536a2294bc2f67852a640655194d39d51a33668762584eca107

Contents?: true

Size: 766 Bytes

Versions: 12

Compression:

Stored size: 766 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Observable #:nodoc:
    extend ActiveSupport::Concern
    included do
      attr_reader :observers
    end

    # Add an observer to this object. This mimics the standard Ruby observable
    # library.
    #
    # Example:
    #
    # <tt>address.add_observer(person)</tt>
    def add_observer(object)
      @observers ||= []
      @observers.push(object)
    end

    # 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:
    #
    # <tt>document.notify_observers(self)</tt>
    def notify_observers(*args)
      @observers.dup.each { |observer| observer.observe(*args) } if @observers
    end
  end
end

Version data entries

12 entries across 12 versions & 6 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/observable.rb
mongoid-with-auth-1.9.4 lib/mongoid/observable.rb
mongoid-rails2-1.9.4 lib/mongoid/observable.rb
mongoid-rails2-1.9.3 lib/mongoid/observable.rb
mongoid-1.9.2 lib/mongoid/observable.rb
sskirby-mongoid-1.9.1 lib/mongoid/observable.rb
mongoid-2.0.0.beta.7 lib/mongoid/observable.rb
mongoid-1.9.1 lib/mongoid/observable.rb
chhean-mongoid-2.0.1.beta1 lib/mongoid/observable.rb
mongoid-2.0.0.beta.5 lib/mongoid/observable.rb
mongoid-1.9.0 lib/mongoid/observable.rb
mongoid-pre-2.0.0.beta1 lib/mongoid/observable.rb