Class: HecksApp::ApplicationPort::Event

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/application_port/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvent

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