module Trailblazer::Activity::DSL::Linear::Helper::ClassMethods
Shortcut functions for the DSL
.
Public Instance Methods
End(semantic)
click to toggle source
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 30 def End(semantic) Activity.End(semantic) end
Id(id)
click to toggle source
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 42 def Id(id) Id.new(id).freeze end
Output(signal, semantic=nil)
click to toggle source
Output( Left, :failure ) Output( :failure ) #=> Output::Semantic
# 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_
click to toggle source
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 46 def Path(track_color: "track_#{rand}", connect_to: nil, before: false, **options, &block) path = Activity::Path(track_name: track_color, **options) activity = Class.new(path) { self.instance_exec(&block) } seq = activity.instance_variable_get(:@state).to_h[:sequence] # TODO: fix @state interface # Strip default ends `Start.default` and `End.success` (if present). seq = seq[1..-1].reject{ |row| row[3][:stop_event] && row[3][:id] == 'End.success' } if connect_to seq = connect_for_sequence(seq, connect_to: connect_to) end # Add the path elements before {End.success}. # Termini (or :stop_event) are to be placed after {End.success}. adds = seq.collect do |row| options = row[3] # the terminus of the path goes _after_ {End.success} into the "end group". insert_method = options[:stop_event] ? Insert.method(:Append) : Insert.method(:Prepend) insert_target = "End.success" # insert before/after insert_target = before if before && connect_to.instance_of?(Trailblazer::Activity::DSL::Linear::Helper::Track) # FIXME: this is a bit hacky, of course! { row: row, insert: [insert_method, insert_target] } end # Connect the Output() => Track(path_track) return Track.new(track_color, adds, {}) end
Subprocess(activity, patch: {})
click to toggle source
Computes the {:outputs} options for {activity}.
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 97 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)
click to toggle source
# 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
end_id(_end)
click to toggle source
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 34 def end_id(_end) "End.#{_end.to_h[:semantic]}" # TODO: use everywhere end
normalize(options, local_keys)
click to toggle source
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 141 def normalize(options, local_keys) # TODO: test me. locals = options.reject { |key, value| ! local_keys.include?(key) } foreign = options.reject { |key, value| local_keys.include?(key) } return foreign, locals end
Private Instance Methods
connect_for_sequence(sequence, connect_to:)
click to toggle source
Connect last row of the {sequence} to the given step via its {Id} Useful when steps needs to be inserted in between {Start} and {connect Id()}.
# File lib/trailblazer/activity/dsl/linear/helper.rb, line 81 def connect_for_sequence(sequence, connect_to:) output, _ = sequence[-1][2][0].(sequence, sequence[-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)] searches = [Search.ById(output, connect_to.value)] if connect_to.instance_of?(Trailblazer::Activity::DSL::Linear::Helper::Id) searches = [Search.Forward(output, connect_to.color)] if connect_to.instance_of?(Trailblazer::Activity::DSL::Linear::Helper::Track) # FIXME: use existing mapping logic! row = sequence[-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 sequence = sequence[0..-2] + [row] sequence end