Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.