rails-erd 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -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/specialization.rb +8 -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 +14 -8
- data/test/unit/config_test.rb +6 -0
- data/test/unit/graphviz_test.rb +10 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f1c2702af0425705ff9d602b686fcb58e1076199c4fb529b201fa023edb3c9e7
|
4
|
+
data.tar.gz: 1ebd9f97445a40bbdb8f15de3d582e26e32796756cb24b038a17451dfa2dec3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc2eb3fa90e42bd77df9bda8fb20d01ac49287f92ed8115abf9bd7b3022450eede790a6a82e369283c1d113d11e106369222b845d19135d192198504306db48
|
7
|
+
data.tar.gz: 1489e87683c7fbe2bf012ff423ff8796fa4e8c2e450ce0473616c6dce6ea5c51ef9fa8d8ad0f001df723f6f972cd3d37277747d1e8e9651863e2b32c077edf9b
|
data/README.md
CHANGED
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
@@ -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/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
@@ -34,9 +34,11 @@ class ActiveSupport::TestCase
|
|
34
34
|
opts = if pk then { :primary_key => pk } else { :id => false } end
|
35
35
|
ActiveRecord::Schema.instance_eval do
|
36
36
|
suppress_messages do
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -47,7 +49,8 @@ class ActiveSupport::TestCase
|
|
47
49
|
def add_column(*args)
|
48
50
|
ActiveRecord::Schema.instance_eval do
|
49
51
|
suppress_messages do
|
50
|
-
|
52
|
+
opts = args.slice!(3) || {}
|
53
|
+
add_column(*args, **opts)
|
51
54
|
end
|
52
55
|
end
|
53
56
|
ActiveRecord::Base.clear_cache!
|
@@ -82,7 +85,7 @@ class ActiveSupport::TestCase
|
|
82
85
|
klass = Object.const_set name.to_sym, Class.new(superklass)
|
83
86
|
|
84
87
|
if superklass == ActiveRecord::Base || superklass.abstract_class?
|
85
|
-
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
|
86
89
|
end
|
87
90
|
klass.class_eval(&block) if block_given?
|
88
91
|
Object.const_get(name.to_sym)
|
@@ -212,15 +215,18 @@ class ActiveSupport::TestCase
|
|
212
215
|
ActiveRecord::Base.connection.drop_table table
|
213
216
|
end
|
214
217
|
|
215
|
-
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")
|
216
221
|
cv = ActiveSupport::DescendantsTracker.class_variable_get(:@@direct_descendants)
|
217
222
|
cv.delete(ActiveRecord::Base)
|
218
223
|
ActiveSupport::DescendantsTracker.class_variable_set(:@@direct_descendants, cv)
|
224
|
+
ActiveSupport::Dependencies::Reference.clear!
|
219
225
|
else
|
220
226
|
ActiveRecord::Base.direct_descendants.clear
|
227
|
+
ActiveSupport::Dependencies::Reference.clear!
|
221
228
|
end
|
222
|
-
|
223
|
-
ActiveSupport::Dependencies::Reference.clear!
|
229
|
+
|
224
230
|
ActiveRecord::Base.clear_cache!
|
225
231
|
end
|
226
232
|
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,7 +1,7 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolf Timmermans
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -162,8 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.6.14
|
165
|
+
rubygems_version: 3.1.6
|
167
166
|
signing_key:
|
168
167
|
specification_version: 4
|
169
168
|
summary: Entity-relationship diagram for your Rails models.
|