8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/yml2erd/diagram.rb', line 8
def create(schema_structure, opts = {})
opts = opts.merge(DEFAULT_OPTIONS)
GraphViz::options(use: 'dot')
g = GraphViz::new('structs', label: opts[:project_name])
table_names = schema_structure.table_names
table_names.each do |table_name|
columns = ''
schema_structure.shared_columns.each { |key, value| columns += build_column(key, value) } unless schema_structure.shared_columns.nil?
schema_structure.columns(table_name).each do |column|
column.each { |key, value| columns += build_column(key, value) }
end
index = schema_structure.index(table_name)
label = build_label(table_name, columns, index)
g.add_nodes(table_name, shape: "record", label: label, style: "rounded")
end
table_names.each do |table_name|
if !schema_structure.relation(table_name).nil? && \
!schema_structure.belongs(table_name).nil?
schema_structure.belongs(table_name).each do |belongs_to|
g.add_edges(belongs_to, table_name)
end
end
end
if opts[:output_style] == 'svg'
g.output(:svg=> opts[:output_path] + '.svg')
else
g.output(:png => opts[:output_path])
end
end
|