Module: RSMP::Notifier
Instance Attribute Summary collapse
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
Instance Method Summary collapse
- #add_listener(listener) ⇒ Object
- #clear_deferred_notify(&block) ⇒ Object
- #deferred_notify(&block) ⇒ Object
- #dequeue_notify ⇒ Object
- #distribute_error(error, options = {}) ⇒ Object
- #initialize_distributor ⇒ Object
- #inspect ⇒ Object
- #notify(message) ⇒ Object
- #notify_without_defer(message) ⇒ Object
- #remove_listener(listener) ⇒ Object
Methods included from Inspect
Instance Attribute Details
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
5 6 7 |
# File 'lib/rsmp/collect/notifier.rb', line 5 def listeners @listeners end |
Instance Method Details
#add_listener(listener) ⇒ Object
38 39 40 41 |
# File 'lib/rsmp/collect/notifier.rb', line 38 def add_listener listener raise ArgumentError unless listener @listeners << listener unless @listeners.include? listener end |
#clear_deferred_notify(&block) ⇒ Object
19 20 21 |
# File 'lib/rsmp/collect/notifier.rb', line 19 def clear_deferred_notify &block @notify_queue = [] end |
#deferred_notify(&block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/rsmp/collect/notifier.rb', line 23 def deferred_notify &block was, @defer_notify = @defer_notify, true yield dequeue_notify ensure @defer_notify = was @notify_queue = [] end |
#dequeue_notify ⇒ Object
32 33 34 35 36 |
# File 'lib/rsmp/collect/notifier.rb', line 32 def dequeue_notify @notify_queue.each { || notify_without_defer } ensure @notify_queue = [] end |
#distribute_error(error, options = {}) ⇒ Object
61 62 63 |
# File 'lib/rsmp/collect/notifier.rb', line 61 def distribute_error error, ={} @listeners.each { |listener| listener.notify_error error, } end |
#initialize_distributor ⇒ Object
13 14 15 16 17 |
# File 'lib/rsmp/collect/notifier.rb', line 13 def initialize_distributor @listeners = [] @defer_notify = false @notify_queue = [] end |
#inspect ⇒ Object
9 10 11 |
# File 'lib/rsmp/collect/notifier.rb', line 9 def inspect "#<#{self.class.name}:#{self.object_id}, #{inspector(:@listeners)}>" end |
#notify(message) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rsmp/collect/notifier.rb', line 48 def notify raise ArgumentError unless if @defer_notify @notify_queue << else notify_without_defer end end |
#notify_without_defer(message) ⇒ Object
57 58 59 |
# File 'lib/rsmp/collect/notifier.rb', line 57 def notify_without_defer @listeners.each { |listener| listener.notify } end |
#remove_listener(listener) ⇒ Object
43 44 45 46 |
# File 'lib/rsmp/collect/notifier.rb', line 43 def remove_listener listener raise ArgumentError unless listener @listeners.delete listener end |