module Substation::Processor
Namespace for chain processors
Attributes
Return executor
@return [Executor]
@api private
Return failure chain
@return [Chain]
@api private
Return the observers
@return [Enumerable<#call>]
@api private
Public Class Methods
Initialize a new instance
@param [Symbol] name
the processor's name
@param [Config] config
the processor's configuration
@return [undefined]
@api private
# File lib/substation/processor.rb, line 27 def initialize(_name, _handler, _config) super @executor = config.executor @observers = config.observers @failure_chain = config.failure_chain end
Public Instance Methods
The response passed on to the next processor in a {Chain}
@param [Response] response
the response returned from invoking the processor
@return [Response]
the response passed on to the next processor in a {Chain}
@api private
# File lib/substation/processor.rb, line 87 def result(response) response end
Test wether chain processing should continue
@param [Response] response
the response returned from invoking the processor
@return [true] for a successful response @return [false] otherwise
@api private
# File lib/substation/processor.rb, line 74 def success?(response) response.success? end
Private Instance Methods
Compose a new object based on input
and output
@param [Request, Response] input
the input as it was before calling {#decompose}
@param [Object] output
the data used to compose a new object
@return [Object]
the composed object
@api private
# File lib/substation/processor.rb, line 142 def compose(input, output) executor.compose(input, output) end
Decompose input
before processing
@param [Request, Response] input
the object to decompose
@return [Object]
the decomposed object
@api private
# File lib/substation/processor.rb, line 126 def decompose(input) executor.decompose(input) end
Execute processor on state
@param [Object] state
the state to execute with
@return [Object]
@api private
# File lib/substation/processor.rb, line 101 def execute(state) compose(state, invoke(decompose(state))) end
Transform response data into something else
@param [Response] response
the response to process
@return [Response]
@api private
# File lib/substation/processor.rb, line 113 def invoke(state) notify_observers(handler.call(state)) end
Notify all observers
@param [Response] response
the response returned from {handler#call}
@return [Response]
@api private
# File lib/substation/processor.rb, line 154 def notify_observers(response) observers.each { |observer| observer.call(response) } response end