Class: Bu::Publisher
- Inherits:
-
Object
- Object
- Bu::Publisher
- Defined in:
- lib/bu/publisher.rb
Class Method Summary collapse
- .publish(event_type, info = {}) ⇒ Object
- .subscribe(subscriber) ⇒ Object
- .topic(topic) ⇒ Object
- .unsubscribe_all ⇒ Object
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_all ⇒ Object
18 19 20 |
# File 'lib/bu/publisher.rb', line 18 def self.unsubscribe_all @@subscribers = {} end |