Class: Attr::Gather::Workflow::DotSerializer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/attr/gather/workflow/dot_serializer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(task_graph) ⇒ DotSerializer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DotSerializer.



10
11
12
# File 'lib/attr/gather/workflow/dot_serializer.rb', line 10

def initialize(task_graph)
  @task_graph = task_graph
end

Instance Method Details

#previewObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
# 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_dotObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
# 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