class Synapse::Command::InterceptorChain

Represents a mechanism for controlling the flow through a chain of interceptors that eventually ends in the invocation of the command handler

Interceptors can either continue the dispatch of a command by calling {#proceed} or choose to block the dispatch by not calling {#proceed} at all. Interceptors can also replace the command message that will be passed on in the chain.

Public Class Methods

new(unit, interceptors, handler) click to toggle source

@param [UnitOfWork] unit The current unit of work for this command dispatch @param [Array<DispatchInterceptor>] interceptors @param [CommandHandler] handler @return [undefined]

# File lib/synapse/command/interceptor_chain.rb, line 14
def initialize(unit, interceptors, handler)
  @unit = unit
  @interceptors = interceptors.each
  @handler = handler
end

Public Instance Methods

proceed(command) click to toggle source

@param [CommandMessage] command The command to proceed with @return [Object] The result of the execution of the command

# File lib/synapse/command/interceptor_chain.rb, line 22
def proceed(command)
  begin
    @interceptors.next.intercept command, @unit, self
  rescue StopIteration
    @handler.handle command, @unit
  end
end