Skip to content

Instantly share code, notes, and snippets.

@segiddins
Last active Aug 29, 2015
Embed
What would you like to do?
PNG of Dependency Graph
gem 'ruby-graphviz'
print_graph("#{test_case.name} (expected)", test_case.result)
print_graph("#{test_case.name}", result)
def print_graph(name, dependency_graph)
require 'graphviz'
# Create a new graph
g = GraphViz.new(:G, :type => :digraph)
add_child = lambda do |graph, parent, child|
cn = g.add_node("#{child.name} (#{child.payload.version})")
g.add_edges(parent, cn)
child.successors.each do |c|
add_child.call(graph, cn, c)
end
end
dependency_graph.root_vertices.values.each do |v|
node = g.add_node("#{v.name} (#{v.payload.version})")
v.successors.each do |s|
add_child.call(g, node, s)
end
end
# Generate output image
g.output(:png => "#{name}.png")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment