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.

Defined Under Namespace

Classes: Unscoped

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Output

Returns a new instance of Output.



118
119
120
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 118

def initialize(filter)
  @filter = filter
end

Instance Method Details

#call(wrap_ctx, original_args, **circuit_options) ⇒ Object

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



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/trailblazer/activity/task_wrap/variable_mapping.rb', line 123

def call( (wrap_ctx, original_args), **circuit_options )
  (original_ctx, original_flow_options), original_circuit_options = original_args

  returned_ctx, _ = wrap_ctx[:return_args] # this is the Context returned from `call`ing the task.
  original_ctx    = wrap_ctx[:vm_original_ctx]

  # let user compute the output.
  output_ctx = @filter.(original_ctx, returned_ctx, **original_circuit_options)

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

  # and then pass on the "new" context.
  return Trailblazer::Activity::Right, [ wrap_ctx, original_args ]
end