Class: Trailblazer::Macro::AssignVariable

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/macro.rb

Overview

Run user_proc with “step interface” and assign its return value to ctx. This is experimental.

Instance Method Summary collapse

Constructor Details

#initialize(return_value_step, variable_name:) ⇒ AssignVariable

name of the ctx variable we want to assign the return_value of user_proc to.



23
24
25
26
# File 'lib/trailblazer/macro.rb', line 23

def initialize(return_value_step, variable_name:)
  @return_value_step  = return_value_step
  @variable_name      = variable_name
end

Instance Method Details

#call(ctx, flow_options, **circuit_options) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/trailblazer/macro.rb', line 28

def call((ctx, flow_options), **circuit_options)
  return_value, ctx = @return_value_step.([ctx, flow_options], **circuit_options)

  ctx[@variable_name] = return_value

  return return_value, ctx
end