Skip to content

Instantly share code, notes, and snippets.

@o-sam-o
Created January 31, 2011 01:56
Show Gist options
  • Save o-sam-o/803527 to your computer and use it in GitHub Desktop.
Save o-sam-o/803527 to your computer and use it in GitHub Desktop.
Use GraphViz to construct a diagram of a Rails act as dag relation
desc 'Uses graphviz to construct a graph of SuperCategories'
task :super_category_graph => :environment do
File.open('super_categories.dot', 'w') do |f|
f.puts "digraph super_categories {\n"
SuperCategory.all.each do |super_category|
super_category.children.each do |child|
f.puts %{"#{super_category.name}" -> "#{child.name}";\n}
end
end
f.puts '}'
end
`dot -Tpng -o'super_categories.png' 'super_categories.dot'`
`open super_categories.png`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment