module Substation::Processor

Namespace for chain processors

Attributes

executor[R]

Return executor

@return [Executor]

@api private

failure_chain[R]

Return failure chain

@return [Chain]

@api private

observers[R]

Return the observers

@return [Enumerable<#call>]

@api private

Public Class Methods

new(_name, _handler, _config) click to toggle source

Initialize a new instance

@param [Symbol] name

the processor's name

@param [Config] config

the processor's configuration

@return [undefined]

@api private

Calls superclass method
# 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

result(response) click to toggle source

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
success?(response) click to toggle source

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(input, output) click to toggle source

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) click to toggle source

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(state) click to toggle source

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
invoke(state) click to toggle source

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_observers(response) click to toggle source

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