Module: Trailblazer::Activity::DSL::Linear::Helper::ClassMethods
- Defined in:
- lib/trailblazer/activity/dsl/linear/helper.rb
Overview
Shortcut functions for the DSL.
Defined Under Namespace
Modules: Patch
Instance Method Summary collapse
- #End(semantic) ⇒ Object
- #end_id(_end) ⇒ Object
- #Id(id) ⇒ Object
-
#normalize(options, local_keys) ⇒ Object
TODO: test me.
-
#Output(signal, semantic = nil) ⇒ Object
Output( Left, :failure ) Output( :failure ) #=> Output::Semantic.
- #Path(track_color: "track_#{rand}", end_id: "path_end_#{rand}", connect_to: nil, **options, &block) ⇒ Object
-
#Subprocess(activity, patch: {}) ⇒ Object
Computes the :outputs options for activity.
- #Track(color, wrap_around: false) ⇒ Object
Instance Method Details
#End(semantic) ⇒ Object
30 31 32 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 30 def End(semantic) Activity.End(semantic) end |
#end_id(_end) ⇒ Object
34 35 36 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 34 def end_id(_end) "End.#{_end.to_h[:semantic]}" # TODO: use everywhere end |
#Id(id) ⇒ Object
42 43 44 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 42 def Id(id) Id.new(id).freeze end |
#normalize(options, local_keys) ⇒ Object
TODO: test me.
138 139 140 141 142 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 138 def normalize(, local_keys) # TODO: test me. locals = .reject { |key, value| ! local_keys.include?(key) } foreign = .reject { |key, value| local_keys.include?(key) } return foreign, locals end |
#Output(signal, semantic = nil) ⇒ Object
Output( Left, :failure )
Output( :failure ) #=> Output::Semantic
24 25 26 27 28 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 24 def Output(signal, semantic=nil) return OutputSemantic.new(signal) if semantic.nil? Activity.Output(signal, semantic) end |
#Path(track_color: "track_#{rand}", end_id: "path_end_#{rand}", connect_to: nil, **options, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 46 def Path(track_color: "track_#{rand}", end_id:"path_end_#{rand}", connect_to:nil, **, &block) # DISCUSS: here, we use the global normalizer and don't allow injection. state = Activity::Path::DSL::State.new(Activity::Path::DSL.OptionsForState(track_name: track_color, end_id: end_id, **)) # TODO: test injecting {:normalizers}. # seq = block.call(state) # state changes. state.instance_exec(&block) seq = state.to_h[:sequence] _end_id = if connect_to end_id else nil end seq = strip_start_and_ends(seq, end_id: _end_id) # don't cut off end unless {:connect_to} is set. if connect_to output, _ = seq[-1][2][0].(seq, seq[-1]) # FIXME: the Forward() proc contains the row's Output, and the only current way to retrieve it is calling the search strategy. It should be Forward#to_h searches = [Search.ById(output, connect_to.value)] row = seq[-1] row = row[0..1] + [searches] + [row[3]] # FIXME: not mutating an array is so hard: we only want to replace the "searches" element, index 2 seq = seq[0..-2] + [row] end # Add the path elements before {End.success}. # Termini (or :stop_event) are to be placed after {End.success}. adds = seq.collect do |row| = row[3] # the terminus of the path goes _after_ {End.success} into the "end group". insert_method = [:stop_event] ? Insert.method(:Append) : Insert.method(:Prepend) { row: row, insert: [insert_method, "End.success"] } end # Connect the Output() => Track(path_track) return Track.new(track_color, adds, {}) end |
#Subprocess(activity, patch: {}) ⇒ Object
Computes the :outputs options for activity.
94 95 96 97 98 99 100 101 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 94 def Subprocess(activity, patch: {}) activity = Patch.customize(activity, options: patch) { task: activity, outputs: Hash[activity.to_h[:outputs].collect { |output| [output.semantic, output] }] } end |
#Track(color, wrap_around: false) ⇒ Object
38 39 40 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 38 def Track(color, wrap_around: false) Track.new(color, [], wrap_around: wrap_around).freeze end |