Module: Doterd
- Defined in:
- lib/doterd.rb,
lib/doterd/version.rb
Defined Under Namespace
Modules: Autodraw, DSL, Renderer
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.config ⇒ Object
Configuration.
-
.dot ⇒ Object
Generate dot source code.
-
.relations ⇒ Object
A relation has the following structure.
-
.tables ⇒ Object
A table has the following structure.
-
.viz(dot_filename = nil) ⇒ Object
Create erd image.
Class Method Details
.config ⇒ Object
Configuration
table_renderer should respond to call(table_name, columns) relation_renderer should respond to call(relation, table_name_1, table_name_2)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/doterd.rb', line 27 def self.config @config ||= { table_renderer: Renderer::Table, relation_renderer: Renderer::Relation, dot_filename: "/tmp/test.dot", output_type: :png, column_description: true, graph_attributes: { concentrate: true, labelloc: :t, nodesep: 0.5, ratio: 1.0, fontsize: 13, pad: "0.4,0.4", rankdir: :LR, margin: "0,0", }, node_attributes:{ shape: "Mrecord", fontsize: 15, margin: "0.07,0.05", penwidth: 1.0, }, edge_attributes: { fontsize: 8, dir: :both, arrowsize: 1.4, penwidth: 1.0, labelangle: 32, labeldistance: 1.8, fontsize: 7, }, } end |
.dot ⇒ Object
Generate dot source code
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/doterd.rb', line 102 def self.dot gattr = Doterd.config[:graph_attributes].map {|k, v| "#{k}=\"#{v}\";\n" }.join nattr = Doterd.config[:node_attributes].map {|k, v| "#{k}=\"#{v}\"" }.join ',' eattr = Doterd.config[:edge_attributes].map {|k, v| "#{k}=\"#{v}\"" }.join ',' nodes = Doterd.tables.map {|t| Doterd.config[:table_renderer].call *t } edges = Doterd.relations.map {|r| Doterd.config[:relation_renderer].call *r } dot = %Q{ digraph adlantis_sp { #{gattr} node [#{nattr}]; edge [#{eattr}]; #{(nodes << '').join(";\n")} #{(edges << '').join(";\n")} } } end |
.relations ⇒ Object
A relation has the following structure
[relation_name, table_name_1, table_name_2]
Available relation_name:
[:_1_N, :_1_1, :_N_1, :_N_N]
table may or may not exist in self.tables
87 88 89 |
# File 'lib/doterd.rb', line 87 def self.relations @relations ||= [] end |
.tables ⇒ Object
A table has the following structure
[
table_name,
{
col_name_1 => [type, description]
col_name_2 => [type]
col_name_3 => []
...
}
]
74 75 76 |
# File 'lib/doterd.rb', line 74 def self.tables @tables ||= [] end |
.viz(dot_filename = nil) ⇒ Object
Create erd image
generate a dot source code, save it to a file and create a erd image out of it.
95 96 97 98 99 |
# File 'lib/doterd.rb', line 95 def self.viz(dot_filename=nil) dot_filename ||= Doterd.config[:dot_filename] File.open(dot_filename, 'w') { |f| f.write dot } system("dot -O -T#{Doterd.config[:output_type]} #{dot_filename}") end |