Class: Substation::Chain
- Inherits:
-
Object
- Object
- Substation::Chain
- Includes:
- Adamantium::Flat, Outgoing
- Defined in:
- lib/substation/chain.rb
Overview
Implements a chain of responsibility for an action
An instance of this class will typically contain (in that order) a few handlers that process the incoming Request object, one handler that calls an action (Pivot), and some handlers that process the outgoing Response object.
Both Incoming and Outgoing handlers must respond to ‘#call(response)` and `#result(response)`.
Defined Under Namespace
Constant Summary collapse
Instance Method Summary collapse
-
#call(request) ⇒ Response::Success, Response::Failure
Call the chain.
Methods included from Outgoing
Instance Method Details
#call(request) ⇒ Response::Success, Response::Failure
Call the chain
Invokes all handlers and returns either the first Response::Failure that it encounters, or if all goes well, the Response::Success returned from the last handler.
155 156 157 158 159 160 161 |
# File 'lib/substation/chain.rb', line 155 def call(request) handlers.inject(request) { |result, handler| response = handler.call(result) return response unless response.success? handler.result(response) } end |