Class: Faulty::Events::Notifier
- Inherits:
-
Object
- Object
- Faulty::Events::Notifier
- Defined in:
- lib/faulty/events/notifier.rb
Overview
The default event dispatcher for Faulty
Instance Method Summary collapse
-
#initialize(listeners = []) ⇒ Notifier
constructor
A new instance of Notifier.
-
#notify(event, payload) ⇒ Object
Notify all listeners of an event.
Constructor Details
#initialize(listeners = []) ⇒ Notifier
Returns a new instance of Notifier.
8 9 10 |
# File 'lib/faulty/events/notifier.rb', line 8 def initialize(listeners = []) @listeners = listeners.freeze end |
Instance Method Details
#notify(event, payload) ⇒ Object
Notify all listeners of an event
If a listener raises an error while handling an event, that error will be captured and written to STDERR.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/faulty/events/notifier.rb', line 21 def notify(event, payload) raise ArgumentError, "Unknown event #{event}" unless EVENTS.include?(event) @listeners.each do |listener| begin listener.handle(event, payload) rescue StandardError => e warn "Faulty listener #{listener.class.name} crashed: #{e.}" end end end |