Sha256: 3e0e2adfc390898dc778b722ebce7a90443fa51d6fc143c5d0fa04165b221a2e

Contents?: true

Size: 765 Bytes

Versions: 1

Compression:

Stored size: 765 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.update(*args) } if @observers
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-2.0.0.alpha lib/mongoid/observable.rb