Class: Switches::Backends::Memory::Bus
- Inherits:
-
Object
- Object
- Switches::Backends::Memory::Bus
- Defined in:
- lib/switches/backends/memory/bus.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Bus
constructor
A new instance of Bus.
- #publish(data) ⇒ Object
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize ⇒ Bus
Returns a new instance of Bus.
5 6 7 |
# File 'lib/switches/backends/memory/bus.rb', line 5 def initialize @listeners = [] end |
Instance Method Details
#clear ⇒ Object
19 20 21 |
# File 'lib/switches/backends/memory/bus.rb', line 19 def clear @listeners.clear end |
#publish(data) ⇒ Object
13 14 15 16 17 |
# File 'lib/switches/backends/memory/bus.rb', line 13 def publish(data) @listeners.each do |listener| listener.call(data) end end |
#subscribe(&block) ⇒ Object
9 10 11 |
# File 'lib/switches/backends/memory/bus.rb', line 9 def subscribe(&block) @listeners.push(block) end |