class Attr::Gather::Workflow::DotSerializer
@api private
Public Class Methods
new(task_graph)
click to toggle source
# File lib/attr/gather/workflow/dot_serializer.rb, line 10 def initialize(task_graph) @task_graph = task_graph end
Public Instance Methods
preview()
click to toggle source
# File lib/attr/gather/workflow/dot_serializer.rb, line 25 def preview Tempfile.open(['task-graph-preview', '.svg']) do |tf| IO.popen("dot -Tsvg -o #{tf.path}", 'w') { |p| p.write(to_dot) } `xdg-open #{tf.path}` end end
to_dot()
click to toggle source
# File lib/attr/gather/workflow/dot_serializer.rb, line 14 def to_dot lines = @task_graph.tsort.map { |t| serialize_row(t) } joined_lines = lines.flatten.map { |l| " #{l}" }.join("\n").strip <<~DOT digraph TaskGraph { #{joined_lines} } DOT end
Private Instance Methods
all_dependants_for_task(input_task)
click to toggle source
# File lib/attr/gather/workflow/dot_serializer.rb, line 39 def all_dependants_for_task(input_task) @task_graph.to_h.keys.select { |task| task.depends_on?(input_task) } end
serialize_row(task)
click to toggle source
# File lib/attr/gather/workflow/dot_serializer.rb, line 34 def serialize_row(task) row = all_dependants_for_task(task).map { |dt| [task, dt] } row.map { |item| "#{item.map(&:name).join(' -> ')};" } end