rails-erd 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- 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/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: 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/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.1
|
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-06-12 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.2.22
|
167
166
|
signing_key:
|
168
167
|
specification_version: 4
|
169
168
|
summary: Entity-relationship diagram for your Rails models.
|