Module: Trailblazer::Activity::DSL::Linear::Normalizer::Inherit

Defined in:
lib/trailblazer/activity/dsl/linear/normalizer/inherit.rb

Overview

“generic”: built by the DSL from options, options that are inherited, so you might not want to record or inherit generic options

Defined Under Namespace

Classes: Record

Class Method Summary collapse

Class Method Details

.compile_recorded_options(ctx, non_symbol_options:) ⇒ Object

Record Figure out what to remember from the options and store it in :recorded_options. Note that this is generic logic not tied to variable_mapping, OutputTuples or anything.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/trailblazer/activity/dsl/linear/normalizer/inherit.rb', line 70

def compile_recorded_options(ctx, non_symbol_options:, **)
  recorded_options = {}

  non_symbol_options
    .find_all { |k, v| k.instance_of?(Record) }
    .collect  do |k, v|
      recorded_options[k.type] = k   # DISCUSS: we overwrite potential data with same type.
    end

  ctx.merge!(
    recorded_options:   recorded_options,
    # add {row.data[:recorded_options]} in Sequence:
    non_symbol_options: non_symbol_options.merge(Strategy.DataVariable() => :recorded_options)
  )
end

.find_row(sequence, id) ⇒ Object



62
63
64
65
# File 'lib/trailblazer/activity/dsl/linear/normalizer/inherit.rb', line 62

def find_row(sequence, id)
  index = Activity::Adds::Insert.find_index(sequence, id)
  sequence[index]
end

.recall_recorded_options(ctx, non_symbol_options:, sequence:, id:, inherit: nil, extensions: []) ⇒ Object

Currently, the :inherit option copies over :extensions from the original step and merges them with new :extensions.

Recall Fetch remembered options and add them to the processed options.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/trailblazer/activity/dsl/linear/normalizer/inherit.rb', line 26

def recall_recorded_options(ctx, non_symbol_options:, sequence:, id:, inherit: nil, extensions: [], **)
  return unless inherit === true || inherit.is_a?(Array)

  # E.g. {variable_mapping: true, wiring_api: true}
  types_to_recall =
    if inherit === true
      # we want to inherit "everything": extensions, output_tuples, variable_mapping
      Hash.new { true }
    else
      inherit.collect { |type| [type, true] }.to_h
    end

  row = find_row(sequence, id) # from this row we're inheriting options.

  # DISCUSS: should we maybe revert the idea of separating options by type?
  # Anyway, key idea here is that Record() users don't have to know these details
  # about symbol vs. non-symbol.
  symbol_options_to_merge     = {}
  non_symbol_options_to_merge = {}

  row.data[:recorded_options].each do |type, record|
    next unless types_to_recall[type]

    target = record.non_symbol_options? ? non_symbol_options_to_merge : symbol_options_to_merge
    target.merge!(record.options)
  end

  ctx[:non_symbol_options] = non_symbol_options_to_merge.merge(non_symbol_options)

  ctx.merge!(symbol_options_to_merge)

  ctx.merge!(
    inherited_recorded_options: row.data[:recorded_options]
  )
end

.Record(options, type:, non_symbol_options: true) ⇒ Object



18
19
20
# File 'lib/trailblazer/activity/dsl/linear/normalizer/inherit.rb', line 18

def Record(options, type:, non_symbol_options: true)
  {Record.new(options, type, non_symbol_options) => nil}
end