Module: Trailblazer::Operation::Nested

Defined in:
lib/trailblazer/operation/nested.rb

Defined Under Namespace

Classes: Caller, Options

Class Method Summary collapse

Class Method Details

.for(step, input, output) ⇒ Object

Please note that the instance_variable_get are here on purpose since the superinternal API is not entirely decided, yet.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trailblazer/operation/nested.rb', line 25

def self.for(step, input, output) # DISCUSS: use builders here?
  invoker            = Caller::Dynamic.new(step)
  invoker            = Caller.new(step) if step.is_a?(Class) && step <= Trailblazer::Operation # interestingly, with < we get a weird nil exception. bug in Ruby?

  options_for_nested = Options.new
  options_for_nested = Options::Dynamic.new(input) if input

  options_for_composer = Options::Output.new
  options_for_composer = Options::Output::Dynamic.new(output) if output

  # This lambda is the strut added on the track, executed at runtime.
  ->(operation, options) do
    result = invoker.(operation, options, options_for_nested.(operation, options)) # TODO: what about containers?

    options_for_composer.(operation, options, result).each { |k,v| options[k] = v }

    result.success? # DISCUSS: what if we could simply return the result object here?
  end
end