Class: Rocketman::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/rocketman/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, payload) ⇒ Event

Returns a new instance of Event.



3
4
5
6
7
# File 'lib/rocketman/event.rb', line 3

def initialize(event, payload)
  @event = event
  @payload = payload
  Rocketman::Registry.register_event(event)
end

Instance Method Details

#notify_consumersObject



9
10
11
12
13
14
15
16
17
# File 'lib/rocketman/event.rb', line 9

def notify_consumers
  consumers = Rocketman::Registry.get_consumers_for(@event)

  return if consumers.nil? || consumers.empty?

  consumers.each do |consumer, action|
    consumer.instance_exec(@payload, &action)
  end
end