Class: Trailblazer::Activity::TaskWrap::Extension::WrapStatic

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

Overview

Extension are used at compile-time with wrap_static, mostly with the dsl gem. WrapStatic extensions are called for setup through Intermediate.config at compile-time. Each extension alters the activity’s wrap_static taskWrap.

Instance Method Summary collapse

Constructor Details

#initialize(extension:) ⇒ WrapStatic

Returns a new instance of WrapStatic.



84
85
86
# File 'lib/trailblazer/activity/task_wrap/extension.rb', line 84

def initialize(extension:)
  @extension = extension
end

Instance Method Details

#call(config:, task:) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/trailblazer/activity/task_wrap/extension.rb', line 88

def call(config:, task:, **)
  # DISCUSS: does it make sense to test the immutable behavior here? What would be the worst outcome?
  task = task.circuit_task # Receives {Schema::Implementation::Task}. DISCUSS: why?

  # Add the extension's task(s) to the activity's {:wrap_static} taskWrap
  # which is stored in the {:config} field.
  wrap_static = config[:wrap_static]                 # the activity's {wrap_static}.
  task_wrap   = wrap_static[task] # the "original" taskWrap for {task}.

  # Overwrite the original task_wrap:
  wrap_static = wrap_static.merge(task => @extension.(task_wrap))

  config.merge(wrap_static: wrap_static) # Return new config hash. This needs to be immutable code!
end