Class: Reru::Dispatcher
- Inherits:
-
Object
- Object
- Reru::Dispatcher
- Defined in:
- lib/reru/dispatcher.rb
Instance Method Summary collapse
- #each(&sink) ⇒ Object
-
#initialize(*sources) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #shutdown(source) ⇒ Object
- #subscribe(*sources) ⇒ Object
- #unsubscribe(source) ⇒ Object
- #update(source, event) ⇒ Object
Constructor Details
#initialize(*sources) ⇒ Dispatcher
Returns a new instance of Dispatcher.
2 3 4 |
# File 'lib/reru/dispatcher.rb', line 2 def initialize(*sources) @sources = sources end |
Instance Method Details
#each(&sink) ⇒ Object
6 7 8 9 |
# File 'lib/reru/dispatcher.rb', line 6 def each(&sink) @sink = sink subscribe(*@sources) end |
#shutdown(source) ⇒ Object
23 24 25 |
# File 'lib/reru/dispatcher.rb', line 23 def shutdown(source) unsubscribe(source) end |
#subscribe(*sources) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/reru/dispatcher.rb', line 11 def subscribe(*sources) sources.each do |source| @sources << source source.add_observer(self) end end |
#unsubscribe(source) ⇒ Object
27 28 29 30 |
# File 'lib/reru/dispatcher.rb', line 27 def unsubscribe(source) source.delete_observer(self) @sources.delete(source) end |
#update(source, event) ⇒ Object
18 19 20 21 |
# File 'lib/reru/dispatcher.rb', line 18 def update(source, event) @sink.call(event) shutdown(source) if event.eos? end |