Module: Trailblazer::Activity::DSL::Linear::Strategy

Included in:
FastTrack, Path, Railway
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

Defined Under Namespace

Classes: BlockProxy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.task_for!(state, type, task, options = {}, &block) ⇒ Object

Called from #step and friends.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 26

def self.task_for!(state, type, task, options={}, &block)
  options = options.merge(dsl_track: type)

  # {#update_sequence} is the only way to mutate the state instance.
  state.update_sequence do |sequence:, normalizers:, normalizer_options:, fields:|
    # Compute the sequence rows.
    options = normalizers.(type, normalizer_options: normalizer_options, options: task, user_options: options.merge(sequence: sequence))

    sequence = Activity::DSL::Linear::DSL.apply_adds_from_dsl(sequence, options)
  end
end

Instance Method Details

#call(args, circuit_options = {}) ⇒ Object

Injects :exec_context so that :instance_methods work.



97
98
99
100
101
102
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 97

def call(args, circuit_options={})
  @activity.(
    args,
    circuit_options.merge(exec_context: new)
  )
end

#inherited(inheriter) ⇒ Object



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

def inherited(inheriter)
  super

  # inherits the {@sequence}, and options.
  inheriter.initialize!(@state.copy)
end

#initialize!(state) ⇒ Object



12
13
14
15
16
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 12

def initialize!(state)
  @state    = state

  recompile_activity!(@state.to_h[:sequence])
end

#invoke(*args) ⇒ Object



104
105
106
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 104

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

#Path(**options, &block) ⇒ Object

syntactically, we can’t access the … end block here.



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

def Path(**options, &block) # syntactically, we can't access the {do ... end} block here.
  BlockProxy.new(options, block)
end

#to_hObject



92
93
94
# File 'lib/trailblazer/activity/dsl/linear/strategy.rb', line 92

def to_h
  @activity.to_h.to_h.merge(activity: @activity)
end