Module: Trailblazer::Activity::DSL::Linear::Helper

Included in:
Strategy
Defined in:
lib/trailblazer/activity/dsl/linear/helper.rb,
lib/trailblazer/activity/dsl/linear/helper/path.rb
more...

Overview

Shortcut functions for the DSL. Those are included in Strategy so they’re available to all Strategy users such as Railway or Operation.

Defined Under Namespace

Modules: Constants, Path

Instance Method Summary collapse

Instance Method Details

#DataVariableObject

[View source]

102
103
104
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 102

def DataVariable
  DataVariableName.new
end

#End(semantic) ⇒ Object

[View source]

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

def End(semantic)
  Normalizer::OutputTuples::End.new(semantic).freeze
end

#end_id(semantic:) ⇒ Object

[View source]

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

def end_id(semantic:, **)
  "End.#{semantic}" # TODO: use everywhere
end

#Extension(*args, **kws) ⇒ Object

[View source]

98
99
100
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 98

def Extension(*args, **kws)
  Normalizer::Extensions.Extension(*args, **kws)
end

#Id(id) ⇒ Object

[View source]

45
46
47
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 45

def Id(id)
  Normalizer::OutputTuples::Id.new(id).freeze
end

#In(**kws) ⇒ Object

[View source]

86
87
88
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 86

def In(**kws)
  VariableMapping::DSL::In(**kws)
end

#Inject(*args, **kws) ⇒ Object

[View source]

94
95
96
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 94

def Inject(*args, **kws)
  VariableMapping::DSL::Inject(*args, **kws)
end

#Out(**kws) ⇒ Object

[View source]

90
91
92
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 90

def Out(**kws)
  VariableMapping::DSL::Out(**kws)
end

#Output(signal, semantic = nil) ⇒ Object

Output( Left, :failure )

Output( :failure ) #=> Output::Semantic
[View source]

27
28
29
30
31
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 27

def Output(signal, semantic = nil)
  return Normalizer::OutputTuples::Output::Semantic.new(signal) if semantic.nil?

  Normalizer::OutputTuples::Output::CustomOutput.new(signal, semantic)
end

#Path(end_task: nil, end_id: nil, **options, &block) ⇒ Object

[View source]

49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 49

def Path(end_task: nil, end_id: nil, **options, &block)
  if end_task # TODO: remove in 2.0.
    Activity::Deprecate.warn caller_locations[0],
      %(Using `:end_task` and `:end_id` in Path() is deprecated, use `:terminus` instead. Please refer to https://trailblazer.to/2.1/docs/activity.html#activity-wiring-api-path-end_task-end_id-deprecation)

    options = options.merge(
      end_task: Activity.End(end_task.to_h[:semantic]),
      end_id:   end_id
    )
  end

  options = options.merge(block: block) if block
  Linear::PathBranch.new(options) # picked up by normalizer.
end

#Subprocess(activity, patch: {}, strict: false) ⇒ Object

Computes the :outputs options for activity.

Parameters:

  • :strict

    If true, all outputs of activity will be wired to the track named after the output’s semantic.

[View source]

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

def Subprocess(activity, patch: {}, strict: false)
  activity = Linear::Patch.customize(activity, options: patch)

  outputs  = activity.to_h[:outputs]
  options  = {}

  if strict
    options.merge!(
      outputs.collect { |output| [Normalizer::OutputTuples::Output::Semantic.new(output.semantic, true), Track(output.semantic)] }.to_h
    )
  end

  {
    task:    activity,
    outputs: outputs.collect { |output| [output.semantic, output] }.to_h,
  }
    .merge(options)
end

#Track(color, wrap_around: false) ⇒ Object

[View source]

41
42
43
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 41

def Track(color, wrap_around: false)
  Normalizer::OutputTuples::Track.new(color, [], wrap_around: wrap_around).freeze
end