Class: EventBus::Registrations

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/event_bus/registrations.rb

Defined Under Namespace

Classes: BlockRegistration, Registration

Instance Method Summary collapse

Constructor Details

#initializeRegistrations

Returns a new instance of Registrations.



10
11
12
# File 'lib/event_bus/registrations.rb', line 10

def initialize
  clear
end

Instance Method Details

#add_block(pattern, &blk) ⇒ Object



29
30
31
# File 'lib/event_bus/registrations.rb', line 29

def add_block(pattern, &blk)
  @listeners << BlockRegistration.new(pattern, blk)
end

#add_method(pattern, listener, method_name) ⇒ Object



25
26
27
# File 'lib/event_bus/registrations.rb', line 25

def add_method(pattern, listener, method_name)
  @listeners << Registration.new(pattern, listener, method_name)
end

#announce(event_name, payload) ⇒ Object



14
15
16
17
18
19
# File 'lib/event_bus/registrations.rb', line 14

def announce(event_name, payload)
  full_payload = {event_name: event_name}.merge(payload)
  @listeners.each do |listener|
    listener.respond(event_name, full_payload)
  end
end

#clearObject



21
22
23
# File 'lib/event_bus/registrations.rb', line 21

def clear
  @listeners = []
end