Class: Faulty::Events::CallbackListener
- Inherits:
-
Object
- Object
- Faulty::Events::CallbackListener
- Defined in:
- lib/faulty/events/callback_listener.rb
Overview
A simple listener implementation that uses callback blocks as handlers
Each event in EVENTS has a method on this class that can be used to register a callback for that event.
Instance Method Summary collapse
- #handle(event, payload) ⇒ void
-
#initialize {|_self| ... } ⇒ CallbackListener
constructor
A new instance of CallbackListener.
Constructor Details
#initialize {|_self| ... } ⇒ CallbackListener
Returns a new instance of CallbackListener.
18 19 20 21 |
# File 'lib/faulty/events/callback_listener.rb', line 18 def initialize @handlers = {} yield self if block_given? end |
Instance Method Details
#handle(event, payload) ⇒ void
This method returns an undefined value.
25 26 27 28 29 30 31 32 |
# File 'lib/faulty/events/callback_listener.rb', line 25 def handle(event, payload) return unless EVENT_SET.include?(event) return unless @handlers.key?(event) @handlers[event].each do |handler| handler.call(payload) end end |