Class: HecksApp::ApplicationPort::Event
- Inherits:
-
Object
- Object
- HecksApp::ApplicationPort::Event
- Includes:
- Singleton
- Defined in:
- lib/application_port/event.rb
Class Method Summary collapse
Instance Method Summary collapse
- #emit(event) ⇒ Object
-
#initialize ⇒ Event
constructor
A new instance of Event.
- #subscribe(subscriber, event) ⇒ Object
Constructor Details
#initialize ⇒ Event
Returns a new instance of Event.
6 7 8 |
# File 'lib/application_port/event.rb', line 6 def initialize @subscriptions = {} end |
Class Method Details
.emit(event) ⇒ Object
14 15 16 |
# File 'lib/application_port/event.rb', line 14 def self.emit(event) instance.emit(event) end |
.subscribe(subscriber, event) ⇒ Object
10 11 12 |
# File 'lib/application_port/event.rb', line 10 def self.subscribe(subscriber, event) instance.subscribe(subscriber, event) end |
Instance Method Details
#emit(event) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/application_port/event.rb', line 23 def emit(event) return unless @subscriptions[event] @subscriptions[event].each do |subscriber| subscriber.notify(event) end end |
#subscribe(subscriber, event) ⇒ Object
18 19 20 21 |
# File 'lib/application_port/event.rb', line 18 def subscribe(subscriber, event) @subscriptions[event] ||= [] @subscriptions[event] << subscriber end |