Class: Trailblazer::Activity::TaskWrap::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/activity/task_wrap/variable_mapping.rb

Overview

TaskWrap step to compute the outgoing Context from the wrapped task. This allows renaming, filtering, hiding, of the options returned from the wrapped task.

Instance Method Summary collapse

Constructor Details

#initialize(filter, id:) ⇒ Output

Returns a new instance of Output.



62
63
64
65
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 62

def initialize(filter, id:)
  @filter = filter
  @id     = id
end

Instance Method Details

#call(wrap_ctx, original_args) ⇒ Object

Runs your filter and replaces the ctx in ‘wrap_ctx` with the filtered one.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 68

def call(wrap_ctx, original_args)
  (original_ctx, _original_flow_options), original_circuit_options = original_args

  returned_ctx, returned_flow_options = wrap_ctx[:return_args]  # this is the Context returned from {call}ing the wrapped user task.
  original_ctx                        = wrap_ctx[@id]           # grab the original ctx from before which was set in the {:input} filter.
  # let user compute the output.
  output_ctx = @filter.(returned_ctx, [original_ctx, returned_flow_options], **original_circuit_options)

  wrap_ctx = wrap_ctx.merge( return_args: [output_ctx, returned_flow_options] )

  # and then pass on the "new" context.
  return wrap_ctx, original_args
end