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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 16bfef1b79087e3017df7723bef8cf286df5a812
4
- data.tar.gz: 7162f90b6dce224a0ec89693e7d307fbc15a9b45
2
+ SHA256:
3
+ metadata.gz: f1c2702af0425705ff9d602b686fcb58e1076199c4fb529b201fa023edb3c9e7
4
+ data.tar.gz: 1ebd9f97445a40bbdb8f15de3d582e26e32796756cb24b038a17451dfa2dec3c
5
5
  SHA512:
6
- metadata.gz: 34e2582512bfe6313f626d4de969eebc328415c97456b1cd151df3e19d75e55cc0b65a9ded7ba0c363d3708072d001266d96657e2a8669ee6a7c4ca7b0cc3ee0
7
- data.tar.gz: 16ddf4ba4c7d640a4c139905fe6f238f76c70cf20712c467ebb9bf9075f0ee6603c0c532114b86bd0e66f7d275f5ae0200802e91c8978a469c6e39208dd3c709
6
+ metadata.gz: dcc2eb3fa90e42bd77df9bda8fb20d01ac49287f92ed8115abf9bd7b3022450eede790a6a82e369283c1d113d11e106369222b845d19135d192198504306db48
7
+ data.tar.gz: 1489e87683c7fbe2bf012ff423ff8796fa4e8c2e450ce0473616c6dce6ea5c51ef9fa8d8ad0f001df723f6f972cd3d37277747d1e8e9651863e2b32c077edf9b
data/README.md CHANGED
@@ -64,6 +64,10 @@ only_recursion_depth: null
64
64
  prepend_primary: false
65
65
  cluster: false
66
66
  splines: spline
67
+ fonts:
68
+ normal: "Arial"
69
+ bold: "Arial Bold"
70
+ italic: "Arial Italic"
67
71
  ```
68
72
 
69
73
  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
- begin
178
- environment_path = "#{path}/config/environment.rb"
179
- require environment_path
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
 
@@ -81,6 +81,12 @@ module RailsERD
81
81
  when :title
82
82
  value.is_a?(String) ? value : !!value
83
83
 
84
+ # nil | <Hash>
85
+ when :fonts
86
+ if value
87
+ Hash(value).transform_keys(&:to_sym)
88
+ end
89
+
84
90
  else
85
91
  value
86
92
  end
@@ -50,7 +50,7 @@ module RailsERD
50
50
 
51
51
  NODE_WIDTH = 130 # @private :nodoc:
52
52
 
53
- FONTS = Config.font_names_based_on_os
53
+ FONTS = Config.font_names_based_on_os.merge(RailsERD.options[:fonts])
54
54
 
55
55
  # Default graph attributes.
56
56
  GRAPH_ATTRIBUTES = {
@@ -30,7 +30,14 @@ module RailsERD
30
30
  end
31
31
 
32
32
  def abstract_from_models(domain, models)
33
- models.select(&:abstract_class?).collect(&:direct_descendants).flatten.collect { |model|
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
@@ -1,7 +1,9 @@
1
1
  require 'graphviz/utils'
2
2
 
3
- def say(message)
4
- puts message unless Rake.application.options.silent
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 #{file}."
69
+ say "Done! Saved diagram to ./#{file}"
64
70
  end
65
71
  end
66
72
 
@@ -1,4 +1,4 @@
1
1
  module RailsERD
2
- VERSION = "1.6.1"
2
+ VERSION = "1.7.0"
3
3
  BANNER = "RailsERD #{VERSION}"
4
4
  end
data/lib/rails_erd.rb CHANGED
@@ -40,6 +40,7 @@ module RailsERD
40
40
  :disconnected, true,
41
41
  :filename, "erd",
42
42
  :filetype, :pdf,
43
+ :fonts, {},
43
44
  :indirect, true,
44
45
  :inheritance, false,
45
46
  :markup, true,
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
- create_table table, opts do |t|
38
- columns.each do |column, type|
39
- t.send type, column
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
- add_column(*args)
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 rescue nil
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("6.0.0.rc1")
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
@@ -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
@@ -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.6.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: 2021-02-16 00:00:00.000000000 Z
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
- rubyforge_project:
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.