Class: Textus::Dispatch::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/dispatch/pipeline.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry:, container:, middleware: []) ⇒ Pipeline

Returns a new instance of Pipeline.



6
7
8
9
10
# File 'lib/textus/dispatch/pipeline.rb', line 6

def initialize(registry:, container:, middleware: [])
  @registry = registry
  @middleware = middleware
  @container = container
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



4
5
6
# File 'lib/textus/dispatch/pipeline.rb', line 4

def container
  @container
end

Class Method Details

.build_command(contract_class, inputs) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/textus/dispatch/pipeline.rb', line 19

def self.build_command(contract_class, inputs)
  members = contract_class.members
  kwargs = members.to_h do |member|
    [member, inputs[member]]
  end
  contract_class.new(**kwargs)
end

Instance Method Details

#dispatch(command, call:) ⇒ Object



12
13
14
15
16
17
# File 'lib/textus/dispatch/pipeline.rb', line 12

def dispatch(command, call:)
  stack = @middleware.reverse.reduce(->(cmd, c) { execute(cmd, c) }) do |next_mw, mw|
    ->(cmd, c) { mw.call(container: @container, command: cmd, call: c, next_handler: next_mw) }
  end
  stack.call(command, call)
end