class Trailblazer::Activity::TaskWrap::Output

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

Public Class Methods

new(filter, id:) click to toggle source
# File lib/trailblazer/activity/task_wrap/variable_mapping.rb, line 67
def initialize(filter, id:)
  @filter = filter
  @id     = id
end

Public Instance Methods

call(wrap_ctx, original_args) click to toggle source

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

# File lib/trailblazer/activity/task_wrap/variable_mapping.rb, line 73
def call(wrap_ctx, original_args)
  (original_ctx, original_flow_options), original_circuit_options = original_args

  return_args = wrap_ctx[:return_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