rails-erd 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/rails_erd/config.rb +2 -0
- data/lib/rails_erd/diagram/graphviz.rb +35 -28
- data/lib/rails_erd/domain.rb +5 -1
- data/lib/rails_erd/domain/attribute.rb +5 -3
- data/lib/rails_erd/version.rb +1 -1
- data/test/test_helper.rb +8 -2
- data/test/unit/diagram_test.rb +1 -8
- data/test/unit/graphviz_test.rb +1 -2
- data/test/unit/rake_task_test.rb +0 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ada96cc38a16ade059a334c1b0c228f1d950799
|
4
|
+
data.tar.gz: 4ce8b31b96b63dd9da6651d932787d78067fbc74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bebbfc35caa2f8db94a5fd444de5342d8fa1ebae29f5d954b7858b2a61ab9dccd7c48093e19dbac693584de9e41e0c50c1030fbd4b30e59e44e58a73838a0f
|
7
|
+
data.tar.gz: 8b6d762b352f2638e482deb1f8e2330af32a040a651264b70cee13d1bfbfce7dc594ede091d8a3df66954be5dc3b0c798e289c0eb64f2979a1f68b946aa6d110
|
data/README.md
CHANGED
@@ -18,6 +18,12 @@ Here's an example entity-relationship diagram that was generated by Rails ERD:
|
|
18
18
|
Browse the [gallery](http://voormedia.github.io/rails-erd/gallery.html) for more example diagrams.
|
19
19
|
|
20
20
|
|
21
|
+
Requirements
|
22
|
+
---------------
|
23
|
+
|
24
|
+
* Ruby 1.9.3+
|
25
|
+
* ActiveRecord 3.x
|
26
|
+
|
21
27
|
Getting started
|
22
28
|
---------------
|
23
29
|
|
@@ -67,7 +73,7 @@ About Rails ERD
|
|
67
73
|
|
68
74
|
Rails ERD was created by Rolf Timmermans (r.timmermans *at* voormedia.com)
|
69
75
|
|
70
|
-
Copyright 2010-
|
76
|
+
Copyright 2010-2015 Voormedia - [www.voormedia.com](http://www.voormedia.com/)
|
71
77
|
|
72
78
|
|
73
79
|
License
|
data/lib/rails_erd/config.rb
CHANGED
@@ -43,7 +43,10 @@ module RailsERD
|
|
43
43
|
# title:: The title to add at the top of the diagram. Defaults to
|
44
44
|
# <tt>"YourApplication domain model"</tt>.
|
45
45
|
class Graphviz < Diagram
|
46
|
-
NODE_LABEL_TEMPLATES = {
|
46
|
+
NODE_LABEL_TEMPLATES = {
|
47
|
+
html: "node.html.erb",
|
48
|
+
record: "node.record.erb"
|
49
|
+
} # @private :nodoc:
|
47
50
|
|
48
51
|
NODE_WIDTH = 130 # @private :nodoc:
|
49
52
|
|
@@ -51,36 +54,35 @@ module RailsERD
|
|
51
54
|
|
52
55
|
# Default graph attributes.
|
53
56
|
GRAPH_ATTRIBUTES = {
|
54
|
-
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
|
61
|
-
:
|
62
|
-
:
|
57
|
+
rankdir: :LR,
|
58
|
+
ranksep: 0.5,
|
59
|
+
nodesep: 0.4,
|
60
|
+
pad: "0.4,0.4",
|
61
|
+
margin: "0,0",
|
62
|
+
concentrate: true,
|
63
|
+
labelloc: :t,
|
64
|
+
fontsize: 13,
|
65
|
+
fontname: FONTS[:bold]
|
63
66
|
}
|
64
67
|
|
65
68
|
# Default node attributes.
|
66
69
|
NODE_ATTRIBUTES = {
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
70
|
+
shape: "Mrecord",
|
71
|
+
fontsize: 10,
|
72
|
+
fontname: FONTS[:normal],
|
73
|
+
margin: "0.07,0.05",
|
74
|
+
penwidth: 1.0
|
72
75
|
}
|
73
76
|
|
74
77
|
# Default edge attributes.
|
75
78
|
EDGE_ATTRIBUTES = {
|
76
|
-
:
|
77
|
-
:
|
78
|
-
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:fontsize => 7
|
79
|
+
fontname: FONTS[:normal],
|
80
|
+
fontsize: 7,
|
81
|
+
dir: :both,
|
82
|
+
arrowsize: 0.9,
|
83
|
+
penwidth: 1.0,
|
84
|
+
labelangle: 32,
|
85
|
+
labeldistance: 1.8,
|
84
86
|
}
|
85
87
|
|
86
88
|
module Simple
|
@@ -101,7 +103,10 @@ module RailsERD
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def specialization_style(specialization)
|
104
|
-
{
|
106
|
+
{ color: :grey60,
|
107
|
+
arrowtail: :onormal,
|
108
|
+
arrowhead: :none,
|
109
|
+
arrowsize: 1.2 }
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
@@ -194,10 +199,12 @@ module RailsERD
|
|
194
199
|
graph.output(filetype => filename.gsub(/\s/,"\\ "))
|
195
200
|
filename
|
196
201
|
rescue RuntimeError => e
|
197
|
-
raise "Saving diagram failed!\nGraphviz produced errors. Verify it
|
198
|
-
|
202
|
+
raise "Saving diagram failed!\nGraphviz produced errors. Verify it " +
|
203
|
+
"has support for filetype=#{options.filetype}, or use " +
|
204
|
+
"filetype=dot.\nOriginal error: #{e.message.split("\n").last}"
|
199
205
|
rescue StandardError => e
|
200
|
-
raise "Saving diagram failed!\nVerify that Graphviz is installed
|
206
|
+
raise "Saving diagram failed!\nVerify that Graphviz is installed " +
|
207
|
+
"and in your path, or use filetype=dot."
|
201
208
|
end
|
202
209
|
end
|
203
210
|
|
@@ -267,7 +274,7 @@ module RailsERD
|
|
267
274
|
|
268
275
|
def relationship_options(relationship)
|
269
276
|
relationship_style(relationship).tap do |options|
|
270
|
-
# Edges with a higher weight are
|
277
|
+
# Edges with a higher weight are optimized to be shorter and straighter.
|
271
278
|
options[:weight] = relationship.strength
|
272
279
|
|
273
280
|
# Indirect relationships should not influence node ranks.
|
data/lib/rails_erd/domain.rb
CHANGED
@@ -114,7 +114,7 @@ module RailsERD
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def models
|
117
|
-
@models ||= @source_models.select { |model| check_model_validity(model) }
|
117
|
+
@models ||= @source_models.select { |model| check_model_validity(model) }.reject { |model| check_habtm_model(model) }
|
118
118
|
end
|
119
119
|
|
120
120
|
def associations
|
@@ -145,5 +145,9 @@ module RailsERD
|
|
145
145
|
def association_description(association)
|
146
146
|
"#{association.name.inspect} on #{association.active_record}"
|
147
147
|
end
|
148
|
+
|
149
|
+
def check_habtm_model(model)
|
150
|
+
model.name.start_with?("HABTM_")
|
151
|
+
end
|
148
152
|
end
|
149
153
|
end
|
@@ -49,7 +49,7 @@ module RailsERD
|
|
49
49
|
|
50
50
|
# Returns +true+ if this attribute is the primary key of the entity.
|
51
51
|
def primary_key?
|
52
|
-
|
52
|
+
@model.primary_key.to_s == name.to_s
|
53
53
|
end
|
54
54
|
|
55
55
|
# Returns +true+ if this attribute is used as a foreign key for any
|
@@ -100,12 +100,14 @@ module RailsERD
|
|
100
100
|
# Returns any non-standard limit for this attribute. If a column has no
|
101
101
|
# limit or uses a default database limit, this method returns +nil+.
|
102
102
|
def limit
|
103
|
-
column.limit.to_i if column.limit != native_type[:limit] and column.limit.respond_to?(:to_i)
|
103
|
+
return column.limit.to_i if column.limit != native_type[:limit] and column.limit.respond_to?(:to_i)
|
104
|
+
column.precision.to_i if column.precision != native_type[:precision] and column.precision.respond_to?(:to_i)
|
104
105
|
end
|
105
106
|
|
106
107
|
# Returns any non-standard scale for this attribute (decimal types only).
|
107
108
|
def scale
|
108
|
-
column.scale.to_i if column.scale != native_type[:scale] and column.scale.respond_to?(:to_i)
|
109
|
+
return column.scale.to_i if column.scale != native_type[:scale] and column.scale.respond_to?(:to_i)
|
110
|
+
0 if column.precision
|
109
111
|
end
|
110
112
|
|
111
113
|
# Returns a string that describes the limit for this attribute, such as
|
data/lib/rails_erd/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,11 @@ require "rubygems"
|
|
2
2
|
require "bundler/setup"
|
3
3
|
|
4
4
|
require "active_record"
|
5
|
-
|
5
|
+
if ActiveSupport::VERSION::MAJOR >= 4
|
6
|
+
require "minitest/autorun"
|
7
|
+
else
|
8
|
+
require "test/unit"
|
9
|
+
end
|
6
10
|
require "rails_erd/domain"
|
7
11
|
|
8
12
|
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
|
@@ -127,13 +131,15 @@ class ActiveSupport::TestCase
|
|
127
131
|
RailsERD::Config.send :remove_const, :CURRENT_CONFIG_FILE
|
128
132
|
RailsERD::Config.send :const_set, :CURRENT_CONFIG_FILE,
|
129
133
|
File.expand_path("../../examples/erdconfig.not_exists", __FILE__)
|
134
|
+
|
135
|
+
RailsERD.options = RailsERD.default_options.merge(Config.load)
|
130
136
|
end
|
131
137
|
|
132
138
|
def reset_domain
|
133
139
|
if defined? ActiveRecord
|
134
140
|
ActiveRecord::Base.descendants.each do |model|
|
135
141
|
model.reset_column_information
|
136
|
-
Object.send :remove_const, model.name.to_sym
|
142
|
+
Object.send :remove_const, model.name.to_sym if Object.const_defined? model.name.to_sym
|
137
143
|
end
|
138
144
|
ActiveRecord::Base.connection.tables.each do |table|
|
139
145
|
ActiveRecord::Base.connection.drop_table table
|
data/test/unit/diagram_test.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require File.expand_path("../test_helper", File.dirname(__FILE__))
|
2
|
+
require "rails_erd/diagram"
|
2
3
|
|
3
4
|
class DiagramTest < ActiveSupport::TestCase
|
4
|
-
def setup
|
5
|
-
load "rails_erd/diagram.rb"
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
RailsERD.send :remove_const, :Diagram
|
10
|
-
end
|
11
|
-
|
12
5
|
def retrieve_entities(options = {})
|
13
6
|
klass = Class.new(Diagram)
|
14
7
|
[].tap do |entities|
|
data/test/unit/graphviz_test.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
require File.expand_path("../test_helper", File.dirname(__FILE__))
|
2
|
+
require "rails_erd/diagram/graphviz"
|
2
3
|
|
3
4
|
class GraphvizTest < ActiveSupport::TestCase
|
4
5
|
def setup
|
5
6
|
RailsERD.options.filetype = :png
|
6
7
|
RailsERD.options.warn = false
|
7
|
-
load "rails_erd/diagram/graphviz.rb"
|
8
8
|
end
|
9
9
|
|
10
10
|
def teardown
|
11
11
|
FileUtils.rm Dir["erd*.*"] rescue nil
|
12
|
-
RailsERD::Diagram.send :remove_const, :Graphviz rescue nil
|
13
12
|
end
|
14
13
|
|
15
14
|
def diagram(options = {})
|
data/test/unit/rake_task_test.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-erd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolf Timmermans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|