Class: Substation::Dispatcher::Action
- Inherits:
-
Object
- Object
- Substation::Dispatcher::Action
- Includes:
- Adamantium::Flat
- Defined in:
- lib/substation/dispatcher.rb
Overview
Encapsulates access to one registered action
Constant Summary collapse
- MissingHandlerError =
Raised when no action class name is configured
Class.new(StandardError)
Class Method Summary collapse
-
.coerce(config) ⇒ Action
private
Coerce the given
name
andconfig
to an Action instance.
Instance Method Summary collapse
-
#call(request) ⇒ Substation::Response
private
Call the action.
Class Method Details
.coerce(config) ⇒ Action
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Coerce the given name
and config
to an Substation::Dispatcher::Action instance
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/substation/dispatcher.rb', line 31 def self.coerce(config) if config.respond_to?(:fetch) action = config.fetch(:action) { raise(MissingHandlerError) } observer = config[:observer] else action = config end action_handler = Utils.coerce_callable(action) observer_handler = Observer.coerce(observer) new(action_handler, observer_handler) end |
Instance Method Details
#call(request) ⇒ Substation::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Call the action
57 58 59 60 61 |
# File 'lib/substation/dispatcher.rb', line 57 def call(request) response = handler.call(request) observer.call(response) response end |