Module: Trailblazer::Developer::Generate
- Defined in:
- lib/trailblazer/developer/generate.rb
Overview
Computes an Intermediate data structure from a TRB-editor.js file.
Defined Under Namespace
Modules: Representer Classes: Arrow, Element, Pipeline
Class Method Summary collapse
- .call(hash) ⇒ Object
- .compute_intermediate(ctx, elements:, start_events:) ⇒ Object
-
.data_for(element) ⇒ Object
private.
- .extract_semantic(label) ⇒ Object
- .find_start_events(ctx, elements:) ⇒ Object
-
.semantic_for(label: nil) ⇒ Object
We currently use the :label field of an arrow to encode an output semantic.
- .transform_from_hash(ctx, hash:, parser: Representer::Activity) ⇒ Object
Class Method Details
.call(hash) ⇒ Object
34 35 36 37 |
# File 'lib/trailblazer/developer/generate.rb', line 34 def call(hash) _, (ctx, _) = Activity::TaskWrap.invoke(Pipeline, [{hash: hash}, {}]) ctx[:intermediate] end |
.compute_intermediate(ctx, elements:, start_events:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trailblazer/developer/generate.rb', line 47 def compute_intermediate(ctx, elements:, start_events:, **) end_events = elements.find_all { |el| el.type == "EndEventTerminate" } # DISCUSS: is it really called TERMINATE? inter = Activity::Schema::Intermediate wiring = elements.collect { |el| data = data_for(el) [inter.TaskRef(el.id, data), el.linksTo.collect { |arrow| inter.Out(semantic_for(**arrow.to_h), arrow.target) } ] } wiring = Hash[wiring] # end events need this stupid special handling # DISCUSS: currently, the END-SEMANTIC is read from the event's label. wiring = wiring.merge(Hash[ end_events.collect do |_end| ref, = wiring.find { |ref, _| ref.id == _end.id } [ref, [inter.Out(semantic_for(**_end.to_h)|| raise, nil)]] # TODO: test the raise, happens when the semantic of an End can't be distinguished. # TODO: don't extract semantic from :label but from :data. end ]) # pp wiring ctx[:intermediate] = inter.new(wiring, end_events.collect(&:id), start_events.collect(&:id)) end |
.data_for(element) ⇒ Object
private
74 75 76 |
# File 'lib/trailblazer/developer/generate.rb', line 74 def data_for(element) {type: element.type}.merge(element.data) end |
.extract_semantic(label) ⇒ Object
86 87 88 |
# File 'lib/trailblazer/developer/generate.rb', line 86 def extract_semantic(label) label.to_sym end |
.find_start_events(ctx, elements:) ⇒ Object
43 44 45 |
# File 'lib/trailblazer/developer/generate.rb', line 43 def find_start_events(ctx, elements:, **) ctx[:start_events] = elements.find_all { |el| el.type == "Event" } end |
.semantic_for(label: nil) ⇒ Object
We currently use the :label field of an arrow to encode an output semantic. The :symbol_style part will be filtered out as semantic. Defaults to :success.
80 81 82 83 84 |
# File 'lib/trailblazer/developer/generate.rb', line 80 def semantic_for(label:nil, **) return :success unless label extract_semantic(label) end |
.transform_from_hash(ctx, hash:, parser: Representer::Activity) ⇒ Object
39 40 41 |
# File 'lib/trailblazer/developer/generate.rb', line 39 def transform_from_hash(ctx, hash:, parser: Representer::Activity, **) ctx[:elements] = parser.new(OpenStruct.new).from_hash(hash).elements end |