Module: Trailblazer::Activity::DSL::Linear
- Defined in:
- lib/trailblazer/activity/dsl/linear.rb,
lib/trailblazer/activity/dsl/linear/state.rb,
lib/trailblazer/activity/dsl/linear/helper.rb,
lib/trailblazer/activity/dsl/linear/compiler.rb,
lib/trailblazer/activity/dsl/linear/strategy.rb,
lib/trailblazer/activity/dsl/linear/normalizer.rb,
lib/trailblazer/activity/dsl/linear/variable_mapping.rb
Overview
TODO: rename!
Defined Under Namespace
Modules: Compiler, DSL, Insert, Normalizer, Patch, Search, Strategy, VariableMapping Classes: Extension, Id, OutputSemantic, Sequence, State, Track
Class Method Summary collapse
- .End(semantic) ⇒ Object
- .end_id(_end) ⇒ Object
- .Id(id) ⇒ Object
-
.Merge(old_seq, new_seq, end_id: "End.success") ⇒ Object
DISCUSS: also Insert.
-
.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
-
.strip_start_and_ends(seq, end_id:) ⇒ Object
TODO: introduce Merge namespace?.
-
.Subprocess(activity, patch: {}) ⇒ Object
Computes the :outputs options for activity.
- .Track(color) ⇒ Object
-
.VariableMapping(input: VariableMapping.default_input, output: VariableMapping.default_output) ⇒ Object
Normalizer-steps to implement :input and :output Returns an Extension instance to be thrown into the ‘step` DSL arguments.
Class Method Details
.End(semantic) ⇒ Object
25 26 27 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 25 def End(semantic) Activity.End(semantic) end |
.end_id(_end) ⇒ Object
29 30 31 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 29 def end_id(_end) "End.#{_end.to_h[:semantic]}" # TODO: use everywhere end |
.Id(id) ⇒ Object
37 38 39 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 37 def Id(id) Id.new(id).freeze end |
.Merge(old_seq, new_seq, end_id: "End.success") ⇒ Object
DISCUSS: also Insert
120 121 122 123 124 |
# File 'lib/trailblazer/activity/dsl/linear.rb', line 120 def Merge(old_seq, new_seq, end_id: "End.success") # DISCUSS: also Insert new_seq = strip_start_and_ends(new_seq, end_id: end_id) seq = Insert.Prepend(old_seq, new_seq, end_id) end |
.normalize(options, local_keys) ⇒ Object
TODO: test me.
118 119 120 121 122 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 118 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
19 20 21 22 23 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 19 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
41 42 43 44 45 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 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 41 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 before End.success - not sure this is bullet-proof. adds = seq.collect do |row| { row: row, insert: [Insert.method(:Prepend), "End.success"] } end # Connect the Output() => Track(path_track) return Track.new(track_color, adds) end |
.strip_start_and_ends(seq, end_id:) ⇒ Object
TODO: introduce Merge namespace?
125 126 127 128 129 |
# File 'lib/trailblazer/activity/dsl/linear.rb', line 125 def strip_start_and_ends(seq, end_id:) # TODO: introduce Merge namespace? cut_off_index = end_id.nil? ? seq.size : Insert.find_index(seq, end_id) # find the "first" end. seq[1..cut_off_index-1] end |
.Subprocess(activity, patch: {}) ⇒ Object
Computes the :outputs options for activity.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 83 def Subprocess(activity, patch: {}) patch.each do |path, patch| activity = Patch.(activity, path, patch) # TODO: test if multiple patches works! end { task: activity, outputs: Hash[activity.to_h[:outputs].collect { |output| [output.semantic, output] }] } end |
.Track(color) ⇒ Object
33 34 35 |
# File 'lib/trailblazer/activity/dsl/linear/helper.rb', line 33 def Track(color) Track.new(color, []).freeze end |
.VariableMapping(input: VariableMapping.default_input, output: VariableMapping.default_output) ⇒ Object
Normalizer-steps to implement :input and :output Returns an Extension instance to be thrown into the ‘step` DSL arguments.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/trailblazer/activity/dsl/linear/variable_mapping.rb', line 7 def self.VariableMapping(input: VariableMapping.default_input, output: VariableMapping.default_output) input = VariableMapping::Input::Scoped.new( Trailblazer::Option::KW( VariableMapping::filter_for(input) ) ) output = VariableMapping::Output::Unscoped.new( Trailblazer::Option::KW( VariableMapping::filter_for(output) ) ) TaskWrap::Extension( merge: TaskWrap::VariableMapping.merge_for(input, output, id: input.object_id), # wraps filters: {Input(input), Output(output)} ) end |