Class: Trailblazer::Workflow::Generate

Inherits:
Activity::Railway
  • Object
show all
Defined in:
lib/trailblazer/workflow/generate.rb

Overview

Computes a Intermediate data structures for every lane from a TRB PRO/editor .json file.

Defined Under Namespace

Modules: Representer Classes: Element, Link

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compile_intermediate(ctx, lane:, start_event:, termini_map:) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/trailblazer/workflow/generate.rb', line 65

def self.compile_intermediate(ctx, lane:, start_event:, termini_map:, **)
  wirings = lane.elements.collect do |node|
    [
      Activity::Schema::Intermediate.TaskRef(node.id, (node.data || {}).merge(type: node.type)),

      node.links.collect do |link|
        Activity::Schema::Intermediate.Out(link.semantic, link.target_id)
      end
    ]
  end.to_h

  intermediate = Activity::Schema::Intermediate.new(
    wirings,
    termini_map,    # {"success"=>:success, "suspend-d15ef8ea-a55f-4eed-a0e8-37f717d21c2f"=>:suspend}
    start_event.id  # start
  )

  ctx[:value] = [lane.id, intermediate]
end

.compute_termini_map(ctx, lane:) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/trailblazer/workflow/generate.rb', line 53

def self.compute_termini_map(ctx, lane:, **)
  terminus_nodes = lane.elements
    .find_all { |node| node.type == :terminus }
    .collect { |node| [node.id, node.id.to_sym] } # {"success" => :success}

  suspend_nodes = lane.elements
    .find_all { |node| node.type == :suspend }
    .collect { |node| [node.id, :suspend] }

  ctx[:termini_map] = (terminus_nodes + suspend_nodes).to_h
end

.default_start_event(ctx, lane:) ⇒ Object

DISCUSS: do we “want” this, should we handle that in the export/convert code and create some Start event?



49
50
51
# File 'lib/trailblazer/workflow/generate.rb', line 49

def self.default_start_event(ctx, lane:, **)
  ctx[:start_event] = lane.elements[0]
end

.find_start_event(ctx, lane:) ⇒ Object



44
45
46
# File 'lib/trailblazer/workflow/generate.rb', line 44

def self.find_start_event(ctx, lane:, **)
  ctx[:start_event] = lane.elements.find { |el| el.id == "Start" }
end

.transform_from_json(ctx, json_document:, parser: Representer::Collaboration) ⇒ Object

Representer



36
37
38
# File 'lib/trailblazer/workflow/generate.rb', line 36

def self.transform_from_json(ctx, json_document:, parser: Representer::Collaboration, **)
  ctx[:structure] = parser.new(OpenStruct.new).from_json(json_document) # DISCUSS: this could be sitting in PRO?
end

Instance Method Details

#lanes(ctx, structure:) ⇒ Object



40
41
42
# File 'lib/trailblazer/workflow/generate.rb', line 40

def lanes(ctx, structure:, **)
  structure.lanes
end