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.



59
60
61
# File 'lib/trailblazer/activity/task_wrap/extension.rb', line 59

def initialize(extension:)
  @extension = extension
end

Instance Method Details

#call(config:, task:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trailblazer/activity/task_wrap/extension.rb', line 63

def call(config:, task:, **)
  # 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))

  # DISCUSS: does it make sense to test the immutable behavior here? What would be the worst outcome?
  config.merge(wrap_static: wrap_static) # Return new config hash. This needs to be immutable code!
end