Class: Synapse::Command::InterceptorChain

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/command/interceptor_chain.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(unit, interceptors, handler) ⇒ undefined

Parameters:

  • unit (UnitOfWork)

    The current unit of work for this command dispatch

  • interceptors (Array)
  • handler (CommandHandler)


14
15
16
17
18
# File 'lib/synapse/command/interceptor_chain.rb', line 14

def initialize(unit, interceptors, handler)
  @unit = unit
  @interceptors = interceptors.each
  @handler = handler
end

Instance Method Details

#proceed(command) ⇒ Object

Returns The result of the execution of the command.

Parameters:

Returns:

  • (Object)

    The result of the execution of the command



22
23
24
25
26
27
28
# 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