Class: EventBus::Registrations
- Inherits:
-
Object
- Object
- EventBus::Registrations
show all
- Includes:
- Singleton
- Defined in:
- lib/event_bus/testing.rb,
lib/event_bus/registrations.rb
Defined Under Namespace
Classes: BlockRegistration, Registration
Instance Method Summary
collapse
Instance Method Details
#add_block(pattern, &blk) ⇒ Object
25
26
27
|
# File 'lib/event_bus/registrations.rb', line 25
def add_block(pattern, &blk)
listeners << BlockRegistration.new(pattern, blk)
end
|
#add_method(pattern, listener, method_name) ⇒ Object
21
22
23
|
# File 'lib/event_bus/registrations.rb', line 21
def add_method(pattern, listener, method_name)
listeners << Registration.new(pattern, listener, method_name)
end
|
#announce(event_name, payload) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/event_bus/registrations.rb', line 10
def announce(event_name, payload)
full_payload = {event_name: event_name}.merge(payload)
listeners.each do |listener|
pass_event_to listener, event_name, full_payload
end
end
|
#clear ⇒ Object
17
18
19
|
# File 'lib/event_bus/registrations.rb', line 17
def clear
listeners.clear
end
|
#last_subscriber ⇒ Object
17
18
19
|
# File 'lib/event_bus/testing.rb', line 17
def last_subscriber
listeners.last
end
|
#on_error(&blk) ⇒ Object
29
30
31
|
# File 'lib/event_bus/registrations.rb', line 29
def on_error(&blk)
@error_handler = blk
end
|
#remove_subscriber(subscriber) ⇒ Object
13
14
15
|
# File 'lib/event_bus/testing.rb', line 13
def remove_subscriber(subscriber)
listeners.delete subscriber
end
|