Class: Gush::Graph
- Inherits:
-
Object
- Object
- Gush::Graph
- Defined in:
- lib/gush/graph.rb
Instance Attribute Summary collapse
-
#end_node ⇒ Object
readonly
Returns the value of attribute end_node.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#start_node ⇒ Object
readonly
Returns the value of attribute start_node.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Instance Method Summary collapse
-
#initialize(workflow, options = {}) ⇒ Graph
constructor
A new instance of Graph.
- #viz ⇒ Object
Constructor Details
#initialize(workflow, options = {}) ⇒ Graph
Returns a new instance of Graph.
9 10 11 12 13 |
# File 'lib/gush/graph.rb', line 9 def initialize(workflow, = {}) @workflow = workflow @filename = .fetch(:filename, "graph.png") @path = .fetch(:path, Pathname.new(Dir.tmpdir).join(filename)) end |
Instance Attribute Details
#end_node ⇒ Object (readonly)
Returns the value of attribute end_node.
7 8 9 |
# File 'lib/gush/graph.rb', line 7 def end_node @end_node end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/gush/graph.rb', line 7 def filename @filename end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/gush/graph.rb', line 7 def path @path end |
#start_node ⇒ Object (readonly)
Returns the value of attribute start_node.
7 8 9 |
# File 'lib/gush/graph.rb', line 7 def start_node @start_node end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
7 8 9 |
# File 'lib/gush/graph.rb', line 7 def workflow @workflow end |
Instance Method Details
#viz ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gush/graph.rb', line 15 def viz @graph = Graphviz::Graph.new(**) @start_node = add_node('start', shape: 'diamond', fillcolor: '#CFF09E') @end_node = add_node('end', shape: 'diamond', fillcolor: '#F56991') # First, create nodes for all jobs @job_name_to_node_map = {} workflow.jobs.each do |job| add_job_node(job) end # Next, link up the jobs with edges workflow.jobs.each do |job| link_job_edges(job) end format = 'png' file_format = path.split('.')[-1] format = file_format if file_format.length == 3 Graphviz::output(@graph, path: path, format: format) end |