class Midnight::BusinessLogic::EventRouter
Public Class Methods
new(handlers_map = {})
click to toggle source
# File lib/midnight/business_logic/event_router.rb, line 6 def initialize(handlers_map = {}) # construction example: # EventRouter.new(SomeEvent => [ # method(:puts) # ]) begin handlers_map.each do |_event_class, handlers| Array(handlers).each do |handler| reject_handlers unless handler.respond_to?(:call) end end rescue ::NoMethodError => e raise e unless e.name == :each reject_handlers end @handlers_map = handlers_map @arity_mismatched = /wrong\s+number\s+of\s+arguments/i freeze end
Public Instance Methods
call(event, **metadata)
click to toggle source
Calls superclass method
Midnight::BusinessLogic::EventDispatcher#call
# File lib/midnight/business_logic/event_router.rb, line 26 def call(event, **metadata) handlers = @handlers_map[event.class] return if handlers.blank? super( event, _event_handlers: Array(handlers), **metadata ) end