class Trailblazer::Activity::TaskWrap::Input

Calls your {@filter} and replaces the original ctx with your returned one.

Public Class Methods

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

Public Instance Methods

call(wrap_ctx, original_args) click to toggle source

{input.call()} is invoked in the circuit. `original_args` are the actual args passed to the wrapped task: [ [ctx, ..], circuit_options ]

# File lib/trailblazer/activity/task_wrap/variable_mapping.rb, line 43
def call(wrap_ctx, original_args)
  # let user compute new ctx for the wrapped task.
  input_ctx = apply_filter(*original_args)

  # decompose the original_args since we want to modify them.
  (original_ctx, original_flow_options), original_circuit_options = original_args

  wrap_ctx = wrap_ctx.merge(@id => original_ctx) # remember the original ctx by the key {@id}.

  # instead of the original Context, pass on the filtered `input_ctx` in the wrap.
  return wrap_ctx, [[input_ctx, original_flow_options], original_circuit_options]
end

Private Instance Methods

apply_filter((ctx, original_flow_options), original_circuit_options) click to toggle source

Invoke the @filter callable with the original circuit interface.

# File lib/trailblazer/activity/task_wrap/variable_mapping.rb, line 59
def apply_filter((ctx, original_flow_options), original_circuit_options)
  @filter.([ctx, original_flow_options], **original_circuit_options) # returns {new_ctx}.
end