rails-erd 1.6.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/rails_erd/cli.rb +15 -7
- data/lib/rails_erd/config.rb +6 -0
- data/lib/rails_erd/diagram/graphviz.rb +1 -1
- data/lib/rails_erd/domain/attribute.rb +1 -1
- data/lib/rails_erd/domain/specialization.rb +8 -1
- data/lib/rails_erd/domain.rb +7 -1
- data/lib/rails_erd/tasks.rake +9 -3
- data/lib/rails_erd/version.rb +1 -1
- data/lib/rails_erd.rb +1 -0
- data/test/test_helper.rb +27 -8
- data/test/unit/attribute_test.rb +10 -11
- data/test/unit/config_test.rb +6 -0
- data/test/unit/graphviz_test.rb +10 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa7b34b79755fba7b09da0d9bd34d02496df7813c2a31c58b6b93c5d5575f25
|
4
|
+
data.tar.gz: c85abffb05d82382d8e32593176f4f377d1e9116128caa29b91a8c621bb67620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f16c8591f2997b9e4fa59d1c10a4e677a5f7c4588e5ee04605e7a517b64278caf391778dcd2f3b56aa38d33055e4deaa9a09aad9ebf9571ab809ede2efed47d
|
7
|
+
data.tar.gz: 700a4ada1bdcae0b32d173f9d0e8b70e24f5cabc5c747d6a3580c1c8cf00d403261239b5fbdc544eb0c1b55b510aad407964854beb6ef4a384114a17c235d28a
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ See the [installation instructions](https://voormedia.github.io/rails-erd/instal
|
|
32
32
|
|
33
33
|
* Install Graphviz 2.22+ ([how?](https://voormedia.github.io/rails-erd/install.html)). On macOS with Homebrew run `brew install graphviz`.
|
34
34
|
|
35
|
+
* on linux - `sudo apt-get install graphviz`
|
36
|
+
|
35
37
|
* Add <tt>gem 'rails-erd', group: :development</tt> to your application's Gemfile
|
36
38
|
|
37
39
|
* Run <tt>bundle exec erd</tt>
|
@@ -64,6 +66,10 @@ only_recursion_depth: null
|
|
64
66
|
prepend_primary: false
|
65
67
|
cluster: false
|
66
68
|
splines: spline
|
69
|
+
fonts:
|
70
|
+
normal: "Arial"
|
71
|
+
bold: "Arial Bold"
|
72
|
+
italic: "Arial Italic"
|
67
73
|
```
|
68
74
|
|
69
75
|
Auto generation
|
data/lib/rails_erd/cli.rb
CHANGED
@@ -174,17 +174,25 @@ module RailsERD
|
|
174
174
|
|
175
175
|
def load_application
|
176
176
|
$stderr.puts "Loading application in '#{File.basename(path)}'..."
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
rescue ::LoadError
|
181
|
-
puts "Please create a file in '#{environment_path}' that loads your application environment."
|
182
|
-
raise
|
183
|
-
end
|
177
|
+
environment_path = "#{path}/config/environment.rb"
|
178
|
+
require environment_path
|
179
|
+
|
184
180
|
if defined? Rails
|
185
181
|
Rails.application.eager_load!
|
186
182
|
Rails.application.config.eager_load_namespaces.each(&:eager_load!) if Rails.application.config.respond_to?(:eager_load_namespaces)
|
187
183
|
end
|
184
|
+
rescue ::LoadError
|
185
|
+
error_message = <<~EOS
|
186
|
+
Tried to load your application environment from '#{environment_path}' but the file was not present.
|
187
|
+
This means that your models might not get loaded fully when the diagram gets buiilt. This can
|
188
|
+
make your entity diagram incomplete.
|
189
|
+
|
190
|
+
However, if you are using ActiveRecord without Rails just make sure your models get
|
191
|
+
loaded eagerly before we generate the ERD (for example, explicitly require your application
|
192
|
+
bootstrap file before calling rails-erd from your Rakefile). We will continue without loading the environment file,
|
193
|
+
and recommend you check your diagram for missing models after it gets generated.
|
194
|
+
EOS
|
195
|
+
puts error_message
|
188
196
|
rescue TypeError
|
189
197
|
end
|
190
198
|
|
data/lib/rails_erd/config.rb
CHANGED
@@ -119,7 +119,7 @@ module RailsERD
|
|
119
119
|
# <tt>:decimal, :precision => 5, :scale => 2/tt>:: decimal (5,2)
|
120
120
|
# <tt>:boolean, :null => false</tt>:: boolean *
|
121
121
|
def type_description
|
122
|
-
type.to_s.tap do |desc|
|
122
|
+
type.to_s.dup.tap do |desc|
|
123
123
|
desc << " #{limit_description}" if limit_description
|
124
124
|
desc << " ∗" if mandatory? && !primary_key? # Add a hair space + low asterisk (Unicode characters)
|
125
125
|
desc << " U" if unique? && !primary_key? && !foreign_key? # Add U if unique but non-key
|
@@ -30,7 +30,14 @@ module RailsERD
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def abstract_from_models(domain, models)
|
33
|
-
models.select(&:abstract_class?)
|
33
|
+
abstract_classes = models.select(&:abstract_class?)
|
34
|
+
direct_descendants = if ActiveRecord.version >= Gem::Version.new("7.0.0")
|
35
|
+
abstract_classes.collect(&:subclasses)
|
36
|
+
else
|
37
|
+
abstract_classes.collect(&:direct_descendants)
|
38
|
+
end
|
39
|
+
|
40
|
+
direct_descendants.flatten.collect { |model|
|
34
41
|
new(domain, domain.entity_by_name(model.superclass.name), domain.entity_by_name(model.name))
|
35
42
|
}
|
36
43
|
end
|
data/lib/rails_erd/domain.rb
CHANGED
@@ -49,7 +49,13 @@ module RailsERD
|
|
49
49
|
# Returns the domain model name, which is the name of your Rails
|
50
50
|
# application or +nil+ outside of Rails.
|
51
51
|
def name
|
52
|
-
defined?
|
52
|
+
return unless defined?(Rails) && Rails.application
|
53
|
+
|
54
|
+
if Rails.application.class.respond_to?(:module_parent)
|
55
|
+
Rails.application.class.module_parent.name
|
56
|
+
else
|
57
|
+
Rails.application.class.parent.name
|
58
|
+
end
|
53
59
|
end
|
54
60
|
|
55
61
|
# Returns all entities of your domain model.
|
data/lib/rails_erd/tasks.rake
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'graphviz/utils'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module ErdRakeHelper
|
4
|
+
def say(message)
|
5
|
+
puts message unless Rake.application.options.silent
|
6
|
+
end
|
5
7
|
end
|
6
8
|
|
7
9
|
namespace :erd do
|
@@ -31,6 +33,8 @@ namespace :erd do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
task :load_models do
|
36
|
+
include ErdRakeHelper
|
37
|
+
|
34
38
|
say "Loading application environment..."
|
35
39
|
Rake::Task[:environment].invoke
|
36
40
|
|
@@ -55,12 +59,14 @@ namespace :erd do
|
|
55
59
|
end
|
56
60
|
|
57
61
|
task :generate => [:check_dependencies, :options, :load_models] do
|
62
|
+
include ErdRakeHelper
|
63
|
+
|
58
64
|
say "Generating Entity-Relationship Diagram for #{ActiveRecord::Base.descendants.length} models..."
|
59
65
|
|
60
66
|
require "rails_erd/diagram/graphviz"
|
61
67
|
file = RailsERD::Diagram::Graphviz.create
|
62
68
|
|
63
|
-
say "Done! Saved diagram to
|
69
|
+
say "Done! Saved diagram to ./#{file}"
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
data/lib/rails_erd/version.rb
CHANGED
data/lib/rails_erd.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -16,6 +16,14 @@ if ActiveSupport::TestCase.respond_to?(:test_order=)
|
|
16
16
|
ActiveSupport::TestCase.test_order = :random
|
17
17
|
end
|
18
18
|
|
19
|
+
# Patch to make Rails 6.1 work.
|
20
|
+
module Kernel
|
21
|
+
# class_eval on an object acts like singleton_class.class_eval.
|
22
|
+
def class_eval(*args, &block)
|
23
|
+
singleton_class.class_eval(*args, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
class ActiveSupport::TestCase
|
20
28
|
include RailsERD
|
21
29
|
|
@@ -26,9 +34,11 @@ class ActiveSupport::TestCase
|
|
26
34
|
opts = if pk then { :primary_key => pk } else { :id => false } end
|
27
35
|
ActiveRecord::Schema.instance_eval do
|
28
36
|
suppress_messages do
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
unless ActiveRecord::Base.connection.table_exists?(table)
|
38
|
+
create_table table, **opts do |t|
|
39
|
+
columns.each do |column, type|
|
40
|
+
t.send type, column
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -39,7 +49,8 @@ class ActiveSupport::TestCase
|
|
39
49
|
def add_column(*args)
|
40
50
|
ActiveRecord::Schema.instance_eval do
|
41
51
|
suppress_messages do
|
42
|
-
|
52
|
+
opts = args.slice!(3) || {}
|
53
|
+
add_column(*args, **opts)
|
43
54
|
end
|
44
55
|
end
|
45
56
|
ActiveRecord::Base.clear_cache!
|
@@ -74,7 +85,7 @@ class ActiveSupport::TestCase
|
|
74
85
|
klass = Object.const_set name.to_sym, Class.new(superklass)
|
75
86
|
|
76
87
|
if superklass == ActiveRecord::Base || superklass.abstract_class?
|
77
|
-
create_table Object.const_get(name.to_sym).table_name, columns, Object.const_get(name.to_sym).primary_key
|
88
|
+
create_table Object.const_get(name.to_sym).table_name, columns, Object.const_get(name.to_sym).primary_key
|
78
89
|
end
|
79
90
|
klass.class_eval(&block) if block_given?
|
80
91
|
Object.const_get(name.to_sym)
|
@@ -171,6 +182,11 @@ class ActiveSupport::TestCase
|
|
171
182
|
|
172
183
|
parts[1..-1].inject([[Object, parts.first.to_sym]]) do |pairs,string|
|
173
184
|
last_parent, last_child = pairs.last
|
185
|
+
# Fixes for Rails 6. No idea if this is actually correct as I can't decipher what the heck is going on in this
|
186
|
+
# code.
|
187
|
+
if last_child == :ActiveRecord || last_child == :primary
|
188
|
+
break []
|
189
|
+
end
|
174
190
|
|
175
191
|
break pairs unless last_parent.const_defined?(last_child)
|
176
192
|
|
@@ -199,15 +215,18 @@ class ActiveSupport::TestCase
|
|
199
215
|
ActiveRecord::Base.connection.drop_table table
|
200
216
|
end
|
201
217
|
|
202
|
-
if ActiveRecord.version >= Gem::Version.new("
|
218
|
+
if ActiveRecord.version >= Gem::Version.new("7.0.0")
|
219
|
+
ActiveSupport::DescendantsTracker.clear(ActiveRecord::Base.subclasses)
|
220
|
+
elsif ActiveRecord.version >= Gem::Version.new("6.0.0.rc1")
|
203
221
|
cv = ActiveSupport::DescendantsTracker.class_variable_get(:@@direct_descendants)
|
204
222
|
cv.delete(ActiveRecord::Base)
|
205
223
|
ActiveSupport::DescendantsTracker.class_variable_set(:@@direct_descendants, cv)
|
224
|
+
ActiveSupport::Dependencies::Reference.clear!
|
206
225
|
else
|
207
226
|
ActiveRecord::Base.direct_descendants.clear
|
227
|
+
ActiveSupport::Dependencies::Reference.clear!
|
208
228
|
end
|
209
|
-
|
210
|
-
ActiveSupport::Dependencies::Reference.clear!
|
229
|
+
|
211
230
|
ActiveRecord::Base.clear_cache!
|
212
231
|
end
|
213
232
|
end
|
data/test/unit/attribute_test.rb
CHANGED
@@ -3,9 +3,9 @@ require File.expand_path("../test_helper", File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
class AttributeTest < ActiveSupport::TestCase
|
5
5
|
def with_native_limit(type, new_limit)
|
6
|
-
ActiveRecord::Base.connection.class_eval do
|
6
|
+
ActiveRecord::Base.connection.singleton_class.class_eval do
|
7
7
|
undef :native_database_types
|
8
|
-
define_method
|
8
|
+
define_method(:native_database_types) do
|
9
9
|
super().tap do |types|
|
10
10
|
types[type][:limit] = new_limit
|
11
11
|
end
|
@@ -13,9 +13,9 @@ class AttributeTest < ActiveSupport::TestCase
|
|
13
13
|
end
|
14
14
|
yield
|
15
15
|
ensure
|
16
|
-
ActiveRecord::Base.connection.class_eval do
|
16
|
+
ActiveRecord::Base.connection.singleton_class.class_eval do
|
17
17
|
undef :native_database_types
|
18
|
-
define_method
|
18
|
+
define_method(:native_database_types) do
|
19
19
|
super()
|
20
20
|
end
|
21
21
|
end
|
@@ -266,14 +266,14 @@ class AttributeTest < ActiveSupport::TestCase
|
|
266
266
|
end
|
267
267
|
|
268
268
|
test "limit should return nil for oddball column types that misuse the limit attribute" do
|
269
|
-
create_model "Business", :location => :integer
|
270
|
-
|
271
|
-
attribute.column.class_eval do
|
272
|
-
define_method :limit do
|
269
|
+
create_model "Business", :location => :integer do
|
270
|
+
define_singleton_method :limit do
|
273
271
|
# https://github.com/voormedia/rails-erd/issues/21
|
274
272
|
{ :srid => 4326, :type => "point", :geographic => true }
|
275
273
|
end
|
276
274
|
end
|
275
|
+
|
276
|
+
attribute = create_attribute(Business, "location")
|
277
277
|
assert_nil attribute.limit
|
278
278
|
end
|
279
279
|
|
@@ -306,13 +306,12 @@ class AttributeTest < ActiveSupport::TestCase
|
|
306
306
|
end
|
307
307
|
|
308
308
|
test "scale should return nil for oddball column types that misuse the scale attribute" do
|
309
|
-
create_model "Kobold", :size => :integer
|
310
|
-
attribute = create_attribute(Kobold, "size")
|
311
|
-
attribute.column.class_eval do
|
309
|
+
create_model "Kobold", :size => :integer do
|
312
310
|
define_method :scale do
|
313
311
|
1..5
|
314
312
|
end
|
315
313
|
end
|
314
|
+
attribute = create_attribute(Kobold, "size")
|
316
315
|
assert_nil attribute.scale
|
317
316
|
end
|
318
317
|
end
|
data/test/unit/config_test.rb
CHANGED
@@ -115,6 +115,12 @@ class ConfigTest < ActiveSupport::TestCase
|
|
115
115
|
assert_equal [:content, :primary_keys], normalize_value(:attributes, ["content", "primary_keys"])
|
116
116
|
end
|
117
117
|
|
118
|
+
test "normalize_value should return hash with symbol keys when key is :fonts and value is a hash." do
|
119
|
+
fonts_value = { "normal" => "Arial", "bold" => "Arial Bold", "italic" => "Arial Italic" }
|
120
|
+
expected = {:normal => "Arial", :bold => "Arial Bold", :italic => "Arial Italic"}
|
121
|
+
assert_equal expected, normalize_value(:fonts, fonts_value)
|
122
|
+
end
|
123
|
+
|
118
124
|
def normalize_value(key, value)
|
119
125
|
RailsERD::Config.new.send(:normalize_value, key, value)
|
120
126
|
end
|
data/test/unit/graphviz_test.rb
CHANGED
@@ -186,6 +186,16 @@ class GraphvizTest < ActiveSupport::TestCase
|
|
186
186
|
assert_equal '"Domain model\n\n"', diagram.graph.graph[:label].to_s
|
187
187
|
end
|
188
188
|
|
189
|
+
test "generate should use default value for fontname attribute" do
|
190
|
+
create_simple_domain
|
191
|
+
assert_equal "\"#{RailsERD::Config.font_names_based_on_os[:bold]}\"", diagram.graph.graph[:fontname].to_s
|
192
|
+
end
|
193
|
+
|
194
|
+
test "generate should add set value for fontname attribute" do
|
195
|
+
create_simple_domain
|
196
|
+
assert_equal '"Arial Bold"', diagram(fonts: {bold: "Arial Bold"}).graph.graph[:fontname].to_s
|
197
|
+
end
|
198
|
+
|
189
199
|
test "generate should add default value for splines attribute" do
|
190
200
|
create_simple_domain
|
191
201
|
assert_equal '"spline"', diagram.graph.graph[:splines].to_s
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-erd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolf Timmermans
|
8
8
|
- Kerri Miller
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -147,7 +147,7 @@ homepage: https://github.com/voormedia/rails-erd
|
|
147
147
|
licenses:
|
148
148
|
- MIT
|
149
149
|
metadata: {}
|
150
|
-
post_install_message:
|
150
|
+
post_install_message:
|
151
151
|
rdoc_options: []
|
152
152
|
require_paths:
|
153
153
|
- lib
|
@@ -162,9 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
|
-
|
166
|
-
|
167
|
-
signing_key:
|
165
|
+
rubygems_version: 3.2.22
|
166
|
+
signing_key:
|
168
167
|
specification_version: 4
|
169
168
|
summary: Entity-relationship diagram for your Rails models.
|
170
169
|
test_files:
|