Class: Primer::Bus
- Inherits:
-
Object
- Object
- Primer::Bus
- Defined in:
- lib/primer/bus.rb,
lib/primer/bus/amqp.rb,
lib/primer/bus/memory.rb
Defined Under Namespace
Instance Method Summary collapse
- #distribute(topic, message) ⇒ Object
-
#initialize ⇒ Bus
constructor
A new instance of Bus.
- #subscribe(topic, &listener) ⇒ Object
- #unsubscribe(topic, &listener) ⇒ Object
- #unsubscribe_all ⇒ Object
Constructor Details
#initialize ⇒ Bus
Returns a new instance of Bus.
7 8 9 |
# File 'lib/primer/bus.rb', line 7 def initialize unsubscribe_all end |
Instance Method Details
#distribute(topic, message) ⇒ Object
11 12 13 14 15 |
# File 'lib/primer/bus.rb', line 11 def distribute(topic, ) topic = topic.to_s return unless @listeners.has_key?(topic) @listeners[topic].each { |cb| cb.call() } end |
#subscribe(topic, &listener) ⇒ Object
17 18 19 |
# File 'lib/primer/bus.rb', line 17 def subscribe(topic, &listener) @listeners[topic.to_s].add(listener) end |
#unsubscribe(topic, &listener) ⇒ Object
21 22 23 |
# File 'lib/primer/bus.rb', line 21 def unsubscribe(topic, &listener) @listeners[topic.to_s].delete(listener) end |
#unsubscribe_all ⇒ Object
25 26 27 |
# File 'lib/primer/bus.rb', line 25 def unsubscribe_all @listeners = Hash.new { |h,k| h[k] = Set.new } end |