| Module | OpenWFE::OwfeObservable |
| In: |
lib/openwfe/util/observable.rb
|
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.
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.
# File lib/openwfe/util/observable.rb, line 59
59: def add_observer (channel, observer=nil, &callback)
60:
61: observer = callback unless observer
62: (@observers[channel] ||= []) << observer
63: observer
64: end
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.
# File lib/openwfe/util/observable.rb, line 72
72: def remove_observer (observer, channel=nil)
73:
74: channels = if channel
75: [ channel ]
76: else
77: @observers.keys
78: end
79:
80: channels.each do |c|
81: do_remove_observer observer, c
82: end
83: end