Class: Dige::GraphvizDiagram::EntityRelationshipDiagram

Inherits:
Dige::GraphvizDiagram show all
Defined in:
lib/dige/graphviz_diagram/entity_relationship_diagram.rb

Constant Summary

Constants inherited from Dige::GraphvizDiagram

DEFAULT_NODE_HEIGHT, DEFAULT_NODE_WIDTH

Instance Attribute Summary

Attributes inherited from Dige::GraphvizDiagram

#associations, #klasses, #parent_child_relations

Instance Method Summary collapse

Methods inherited from Dige::GraphvizDiagram

#debug_inspect, #edge, #edge_settings, #generate_diagram, #graph_settings, #header, #node, #node_settings, #quote, #random_color, #settings

Methods included from ClassBase

#initialize

Instance Method Details

#generate(file = ENV['FILE'], type = 'png') ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dige/graphviz_diagram/entity_relationship_diagram.rb', line 2

def generate(file = ENV['FILE'], type = 'png')
  generate_diagram(file + "_entity_relationship_model", type) do
    assocs = associations.all.collect do |assoc|
      clr = random_color
      if assoc.table_name
        [{ :from => assoc.table_name, :to => assoc.from_table_name }, { :from => assoc.table_name, :to => assoc.to_table_name }]
      else
        [{ :from => assoc.from_table_name, :to => assoc.to_table_name }]
      end
    end.flatten

    klasses.all.collect { |klass| node(klass.table_name, :associations_count => klass.associations_count) }.uniq.sort +
    associations.all.collect { |assoc| assoc.table_name ? node(assoc.table_name) : nil }.compact.uniq.sort +
    assocs.uniq.collect { |ass| edge(ass[:from], ass[:to], true, { :color => random_color}) }.uniq.sort
  end    
end