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
Class Method Summary collapse
- .call(hash) ⇒ Object
-
.semantic_for(label: nil) ⇒ Object
We currently use the :label field of an arrow to encode an output semantic.
Class Method Details
.call(hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trailblazer/developer/generate.rb', line 29 def call(hash) elements = Representer::Activity.new(OpenStruct.new).from_hash(hash).elements start_events = elements.find_all { |el| el.type == "Event" } end_events = elements.find_all { |el| el.type == "EndEventTerminate" }# DISCUSS: TERMINATE? inter = Activity::Schema::Intermediate wiring = elements.collect { |el| [inter.TaskRef(el.id, el.data), el.linksTo.collect { |arrow| inter.Out(semantic_for(arrow.to_h), arrow.target) } ] } wiring = Hash[wiring] # end events need this stupid special handling wiring = wiring.merge(Hash[ end_events.collect do |_end| ref, outputs = wiring.find { |ref, _| ref.id == _end.id } [ref, [inter.Out(semantic_for(_end.to_h), nil)]] end ]) # pp wiring inter.new(wiring, end_events.collect(&:id), start_events.collect(&:id)) 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.
57 58 59 60 61 62 |
# File 'lib/trailblazer/developer/generate.rb', line 57 def semantic_for(label:nil, **) return :success unless label m = label.match(/:(\w+)/) return m[1].to_sym end |