Module: Trailblazer::Developer::Activity::Graph
- Defined in:
- lib/trailblazer/developer/activity.rb
Defined Under Namespace
Class Method Summary collapse
-
.to_model(graph, id: "some-process") ⇒ Object
Model Generic representation of the graph, ready for rendering.
Class Method Details
.to_model(graph, id: "some-process") ⇒ Object
Returns Model Generic representation of the graph, ready for rendering.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trailblazer/developer/activity.rb', line 18 def self.to_model(graph, id: "some-process") # rubocop:disable Metrics/AbcSize start_events = graph.find_all("Start.default") # FIXME. this is a static assumption. end_events = graph.find_all { |node| graph.successors(node).size.zero? } tasks = graph.find_all { |_node| true } tasks -= start_events tasks -= end_events # transform nodes into BPMN elements. start_events = start_events.collect do |evt| Task.new(evt[:id], evt[:id], evt, Incomings(graph, evt), Outgoings(graph, evt)) end end_events = end_events.collect do |evt| Task.new(evt[:id], evt[:id], evt, Incomings(graph, evt), Outgoings(graph, evt)) end tasks = tasks.collect { |evt| Task.new(evt[:id], evt[:id], evt, Incomings(graph, evt), Outgoings(graph, evt)) } edges = (start_events + end_events + tasks).collect { |task| [task.incoming, task.outgoing] }.flatten(2).uniq Model.new(id, start_events, end_events, tasks, edges) end |