Class: Primer::Bus

Inherits:
Object
  • Object
show all
Defined in:
lib/primer/bus.rb,
lib/primer/bus/amqp.rb,
lib/primer/bus/memory.rb

Direct Known Subclasses

AMQP, Memory

Defined Under Namespace

Classes: AMQP, Memory

Instance Method Summary collapse

Constructor Details

#initializeBus

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, message)
  topic = topic.to_s
  return unless @listeners.has_key?(topic)
  @listeners[topic].each { |cb| cb.call(message) }
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_allObject



25
26
27
# File 'lib/primer/bus.rb', line 25

def unsubscribe_all
  @listeners = Hash.new { |h,k| h[k] = Set.new }
end