Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'graphviz'
def each_model
ObjectSpace.each_object(Class) do |klass|
yield klass if klass.ancestors.include?(ActiveRecord::Base) && klass != ActiveRecord::Base
end
end
graph_viz = GraphViz::new('Gemfile', {:concentrate => true, :normalize => true, :nodesep => 0.55})
graph_viz.edge[:fontname] = graph_viz.node[:fontname] = 'Arial, Helvetica, SansSerif'
graph_viz.edge[:fontsize] = 12
models = {}
each_model do |model|
name = model.to_s
models[name] = graph_viz.add_node(name, { :shape => 'box3d', :fontsize => 16, :style => 'filled', :fillcolor => '#B9B9D5' } )
end
each_model do |model|
model_name = model.to_s
model.reflect_on_all_associations.each do |assoc|
assoc_name = assoc.name.to_s.singularize.camelize
graph_viz.add_edge(models[model_name], models[assoc_name], { :weight => 2 }) unless models[assoc_name].nil?
end
end
graph_viz.output( :png => 'activerecord_associations.png' )
@vijaydev

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.