Class: Trailblazer::Activity::TaskWrap::Input

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(filter, id:) ⇒ Input

Returns a new instance of Input.



29
30
31
32
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 29

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

Instance Method Details

#call(wrap_ctx, original_args) ⇒ Object

Trailblazer::Activity::TaskWrap::Input.inputinput.call() is invoked in the taskWrap pipeline. original_args are the actual args passed to the wrapped task: [ [ctx, ..], circuit_options ] We now swap the ctx in original_args and our filtered one. The original “outside” ctx is keyed in wrap_ctx with the filter ID.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 38

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