Class: Gush::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/gush/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow, options = {}) ⇒ Graph

Returns a new instance of Graph.



5
6
7
8
9
# 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

Instance Attribute Details

#end_nodeObject (readonly)

Returns the value of attribute end_node.



3
4
5
# File 'lib/gush/graph.rb', line 3

def end_node
  @end_node
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/gush/graph.rb', line 3

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/gush/graph.rb', line 3

def path
  @path
end

#startObject (readonly)

Returns the value of attribute start.



3
4
5
# File 'lib/gush/graph.rb', line 3

def start
  @start
end

#workflowObject (readonly)

Returns the value of attribute workflow.



3
4
5
# File 'lib/gush/graph.rb', line 3

def workflow
  @workflow
end

Instance Method Details

#vizObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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