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.

Methods

Public Instance methods

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.

[Source]

    # 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.

[Source]

    # 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

Protected Instance methods

Observable classes do call this method to notify their observers.

Returns true if there was an observer registered.

[Source]

    # File lib/openwfe/util/observable.rb, line 93
93:             def onotify (channel, *args)
94: 
95:                 do_notify(:all, channel, *args)
96:                 do_notify(channel, channel, *args)
97:             end

[Validate]