Module: OpenWFE::OwfeObservable

Included in:
ExpressionPool, ParticipantMap
Defined in:
lib/openwfe/util/observable.rb

Overview

A classic : this mixin gathers observability methods. It assumes that customer classes will have a @observers instance variable available. This mixin is chiefly used by the ExpressionPool class.

Instance Method Summary collapse

Instance Method Details

#add_observer(channel, observer = nil, &callback) ⇒ Object

Observers will register themselves to the Observable via this method.

An observer is an instance which responds to call(channel, *args)

Returns the observer object (or the block’s Proc object), could be useful when removing the observer.



59
60
61
62
63
64
# File 'lib/openwfe/util/observable.rb', line 59

def add_observer (channel, observer=nil, &callback)

    observer = callback unless observer
    (@observers[channel] ||= []) << observer
    observer
end

#remove_observer(observer, channel = nil) ⇒ Object

Removes an observer (this obviously doesn’t work well when the actual observer is a block). If a channel is given, the observer will only get removed when registered for that channel.



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/openwfe/util/observable.rb', line 72

def remove_observer (observer, channel=nil)

    channels = if channel
        [ channel ]
    else
        @observers.keys
    end

    channels.each do |c|
        do_remove_observer observer, c
    end
end