Class: Bu::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/bu/publisher.rb

Class Method Summary collapse

Class Method Details

.publish(event_type, info = {}) ⇒ Object



13
14
15
16
# File 'lib/bu/publisher.rb', line 13

def self.publish(event_type, info = {})
  subscribed_to_topic = subscribers[event_type] || []
  subscribed_to_topic.each { |subscriber| subscriber.event(event_type, info) }
end

.subscribe(subscriber) ⇒ Object



5
6
7
# File 'lib/bu/publisher.rb', line 5

def self.subscribe(subscriber)
  subscriber.subscribed_to.each { |subscribed_topic| topic(subscribed_topic) << subscriber }
end

.topic(topic) ⇒ Object



9
10
11
# File 'lib/bu/publisher.rb', line 9

def self.topic(topic)
  subscribers[topic.to_sym] ||= Set.new
end

.unsubscribe_allObject



18
19
20
# File 'lib/bu/publisher.rb', line 18

def self.unsubscribe_all
  @@subscribers = {}
end