class Gush::Graph

Attributes

end_node[R]
filename[R]
path[R]
start[R]
workflow[R]

Public Class Methods

new(workflow, options = {}) click to toggle source
# File lib/gush/graph.rb, line 5
def initialize(workflow, options = {})
  @workflow = workflow
  @filename = options.fetch(:filename, "graph.png")
  @path = options.fetch(:path, Pathname.new(Dir.tmpdir).join(filename))
end

Public Instance Methods

viz() click to toggle source
# File lib/gush/graph.rb, line 11
def viz
  GraphViz.new(:G, graph_options) do |graph|
    set_node_options!(graph)
    set_edge_options!(graph)

    @start = graph.start(shape: 'diamond', fillcolor: '#CFF09E')
    @end_node = graph.end(shape: 'diamond', fillcolor: '#F56991')

    workflow.jobs.each do |job|
      add_job(graph, job)
    end

    graph.output(png: path)
  end
end

Private Instance Methods

add_job(graph, job) click to toggle source
# File lib/gush/graph.rb, line 32
def add_job(graph, job)
  name = job.class.to_s
  graph.add_nodes(job.name, label: name)

  if job.incoming.empty?
    graph.add_edges(start, job.name)
  end

  if job.outgoing.empty?
    graph.add_edges(job.name, end_node)
  else
    job.outgoing.each do |id|
      outgoing_job = workflow.find_job(id)
      graph.add_edges(job.name, outgoing_job.name)
    end
  end
end
edge_options() click to toggle source
# File lib/gush/graph.rb, line 81
def edge_options
  {
    dir: "forward",
    penwidth: 1,
    color: "#555555"
  }
end
graph_options() click to toggle source
# File lib/gush/graph.rb, line 62
def graph_options
  {
    type: :digraph,
    dpi: 200,
    compound: true,
    rankdir: "LR",
    center: true
  }
end
node_options() click to toggle source
# File lib/gush/graph.rb, line 72
def node_options
  {
    shape: "ellipse",
    style: "filled",
    color: "#555555",
    fillcolor: "white"
  }
end
set_edge_options!(graph) click to toggle source
# File lib/gush/graph.rb, line 56
def set_edge_options!(graph)
  edge_options.each do |key, value|
    graph.edge[key] = value
  end
end
set_node_options!(graph) click to toggle source
# File lib/gush/graph.rb, line 50
def set_node_options!(graph)
  node_options.each do |key, value|
    graph.node[key] = value
  end
end