Class: Commandos::Dispatcher
- Inherits:
-
Object
- Object
- Commandos::Dispatcher
- Defined in:
- lib/commandos/dispatcher.rb
Instance Method Summary collapse
- #dispatch(command) ⇒ Object
-
#initialize(registry: nil) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(registry: nil) ⇒ Dispatcher
Returns a new instance of Dispatcher.
6 7 8 |
# File 'lib/commandos/dispatcher.rb', line 6 def initialize(registry: nil) @registry = registry end |
Instance Method Details
#dispatch(command) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/commandos/dispatcher.rb', line 10 def dispatch(command) raise RegistryNotFound if registry.nil? raise UnknownCommand unless command.kind_of? IAmACommand registry.find_by command do |handler| handler = handler.new command result = handler.call if block_given? yield result end return result end end |