Class: Trailblazer::Activity::DSL::Linear::Strategy

Inherits:
Object
  • Object
show all
Extended by:
Helper, Merge::DSL
Includes:
Helper::Constants
Defined in:
lib/trailblazer/activity/dsl/linear/strategy.rb

Overview

Trailblazer::Activity

holds the {@schema}
provides DSL step/merge!
provides DSL inheritance
provides run-time {call}
maintains the {state} with {seq} and normalizer options

This could be a class but we decided to leave it as a module that then gets extended into Helper::Path and friends. This won’t trigger the inheritance (because) there is nothing to inherit.

Direct Known Subclasses

FastTrack, Path, Railway

Defined Under Namespace

Modules: DSL

Class Method Summary collapse

Methods included from Helper

DataVariable, End, Extension, Id, In, Inject, Out, Output, Path, Subprocess, Track, end_id

Methods included from Merge::DSL

merge!

Class Method Details

.call(args, **circuit_options) ⇒ Object

Injects :exec_context so that :instance_methods work.



102
103
104
105
106
107
108
109
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 102

def call(args, **circuit_options)
  activity = @state.get(:activity)

  activity.(
    args,
    **circuit_options.merge(exec_context: new)
  )
end

.compile_strategy!(strategy_dsl, **options) ⇒ Object

Used only once per strategy class body.



77
78
79
80
81
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 77

def compile_strategy!(strategy_dsl, **options)
  options = DSL.OptionsForSequenceBuilder(strategy_dsl, **options)

  compile_strategy_for!(**options)
end

.compile_strategy_for!(sequence:, normalizers:, **normalizer_options) ⇒ Object



83
84
85
86
87
88
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 83

def compile_strategy_for!(sequence:, normalizers:, **normalizer_options)
  @state.update!(:normalizers)        { normalizers }        # immutable
  @state.update!(:normalizer_options) { normalizer_options } # immutable

  recompile!(sequence)
end

.copy(value) ⇒ Object

FIXME: move to State#dup



174
175
176
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 174

def self.copy(value, **) # DISCUSS: should that be here?
  value.copy
end

.inherited(inheriter) ⇒ Object



23
24
25
26
27
28
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 23

def inherited(inheriter)
  super

  # Inherits the {State:sequencer} and other options without recomputing anything.
  inheriter.initialize!(@state.copy)
end

.initialize!(state) ⇒ Object



19
20
21
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 19

def initialize!(state)
  @state = state
end

.invoke(*args, **kws) ⇒ Object



111
112
113
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 111

def invoke(*args, **kws)
  TaskWrap.invoke(self, *args, **kws)
end

.recompile!(sequence) ⇒ Object

DISCUSS: this should be the only way to “update” anything on state.



69
70
71
72
73
74
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 69

def recompile!(sequence)
  activity = recompile_activity(sequence)

  @state.update!(:sequence) { |*| sequence }
  @state.update!(:activity) { |*| activity }
end

.step(*args, &block) ⇒ Object

We forward ‘step` to the Dsl (State) object. Recompiling the activity/sequence is a matter specific to Strategy (Railway etc).



33
34
35
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 33

def step(*args, &block)
  recompile_activity_for(:step, *args, &block)
end

.terminus(*args) ⇒ Object



37
38
39
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 37

def terminus(*args)
  recompile_activity_for(:terminus, *args)
end

.to_hObject

Mainly used for introspection.



91
92
93
94
95
96
97
98
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 91

def to_h
  activity = @state.get(:activity)

  activity.to_h.to_h.merge(
    activity: activity,
    sequence: @state.get(:sequence)
  )
end