annotaterb 4.18.0 → 4.19.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0276a5044aa1b444f73aac5612004ce9a8c05c6d47634fb2e8798c24a442fed5
4
- data.tar.gz: 58cd27cb187989b06c459979ac0152db9dfdb54d671b9348980c244caa7981a6
3
+ metadata.gz: '0759110968217261a67bb8c519e55398ff9f43392e6cc4771bbebf5f97ce0395'
4
+ data.tar.gz: d179acc1d279901b547475d5ee87d46346d671e083ef233d2e65e1a7c8d3f277
5
5
  SHA512:
6
- metadata.gz: ac0f491e7022299fc96029950c5edf2b0e05aa38e9f3198ec37acbd04275888be493f4202f31295e8db0ad7737cc03d2c6b52e5fbb51c24418ef92f40da77a13
7
- data.tar.gz: 914216a38c137682acb6e2b58154c3af47dba3b0ebb424b69194a59c3939cfdd01c00d0f75a10bb51800f2ea6ce3f4dc97f3cdcd592ff7f77e7cafc906cd660f
6
+ metadata.gz: 8c0c8deaf4685925e3992f0adc33ecc2d92c49049eea38e44881d510b06128e031569ab242b80e160d534b369985a4eb9bb28612682d10c7a4e254f18030078e
7
+ data.tar.gz: 1f37df086f3c6afd475e684bdc8458fd3ffe70ff245f2dc6b14786cd889e3b2107269064344f79c27425f46e0f599b3a6d3d4e7662844523c7a22bd799c49fc5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.18.0](https://github.com/drwl/annotaterb/tree/v4.18.0) (2025-08-04)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.17.0...v4.18.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Feature request: support for multi database [\#188](https://github.com/drwl/annotaterb/issues/188)
10
+
11
+ **Closed issues:**
12
+
13
+ - Does not run on rollback with multiple databases [\#244](https://github.com/drwl/annotaterb/issues/244)
14
+ - classified\_sort and polymorphic associations [\#236](https://github.com/drwl/annotaterb/issues/236)
15
+ - --show-migration also annotates the primary DB's schema version for models referencing the secondary DB [\#233](https://github.com/drwl/annotaterb/issues/233)
16
+ - Annotations are not added on top of model files when columns'`comment:` contains Japanese characters in migrations [\#200](https://github.com/drwl/annotaterb/issues/200)
17
+ - Feature: further customization to achieve more compact annotations [\#150](https://github.com/drwl/annotaterb/issues/150)
18
+ - Version 5 change list [\#127](https://github.com/drwl/annotaterb/issues/127)
19
+ - Reformat Column Comments [\#117](https://github.com/drwl/annotaterb/issues/117)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - Bump version to v4.18.0 [\#246](https://github.com/drwl/annotaterb/pull/246) ([drwl](https://github.com/drwl))
24
+ - Run on rollback in app with multiple databases [\#245](https://github.com/drwl/annotaterb/pull/245) ([z1lk](https://github.com/z1lk))
25
+ - Speed up AnnotationDecider [\#243](https://github.com/drwl/annotaterb/pull/243) ([DRBragg](https://github.com/DRBragg))
26
+ - Add AnnotateRb::Runner.running? method [\#242](https://github.com/drwl/annotaterb/pull/242) ([thewatts](https://github.com/thewatts))
27
+ - fix: --show-migration to use per-model database connections [\#241](https://github.com/drwl/annotaterb/pull/241) ([OdenTakashi](https://github.com/OdenTakashi))
28
+ - Fix: Support Japanese characters in column names [\#239](https://github.com/drwl/annotaterb/pull/239) ([tonystrawberry](https://github.com/tonystrawberry))
29
+ - Fix classified\_sort to group polymorphic association columns together [\#238](https://github.com/drwl/annotaterb/pull/238) ([garriguv](https://github.com/garriguv))
30
+ - Generate changelog for v4.17.0 [\#235](https://github.com/drwl/annotaterb/pull/235) ([drwl](https://github.com/drwl))
31
+
3
32
  ## [v4.17.0](https://github.com/drwl/annotaterb/tree/v4.17.0) (2025-07-14)
4
33
 
5
34
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.16.0...v4.17.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.18.0
1
+ 4.19.0
@@ -7,17 +7,16 @@ module AnnotateRb
7
7
  def call(options)
8
8
  options[:require].count > 0 && options[:require].each { |path| require path }
9
9
 
10
- if defined?(::Rails::Application)
11
- if defined?(::Zeitwerk)
12
- # Delegate to Zeitwerk to load stuff as needed
13
- else
14
- klass = ::Rails::Application.send(:subclasses).first
15
- klass.eager_load!
16
- end
10
+ if defined?(::Zeitwerk)
11
+ # Delegate to Zeitwerk to load stuff as needed
12
+ # (Supports both Rails and non-Rails applications)
13
+ elsif defined?(::Rails::Application)
14
+ klass = ::Rails::Application.send(:subclasses).first
15
+ klass.eager_load!
17
16
  else
18
17
  model_files = ModelAnnotator::ModelFilesGetter.call(options)
19
18
  model_files&.each do |model_file|
20
- require model_file
19
+ require File.join(*model_file)
21
20
  end
22
21
  end
23
22
  end
@@ -59,7 +59,7 @@ module AnnotateRb
59
59
  end
60
60
 
61
61
  def build
62
- version = migration_version_for_model(@model)
62
+ version = @model.migration_version
63
63
  table_name = @model.table_name
64
64
  table_comment = @model.connection.try(:table_comment, @model.table_name)
65
65
  max_size = @model.max_schema_info_width
@@ -68,30 +68,6 @@ module AnnotateRb
68
68
  version: version, table_name: table_name, table_comment: table_comment,
69
69
  max_size: max_size, model: @model).build
70
70
  end
71
-
72
- private
73
-
74
- def migration_version_for_model(model)
75
- return 0 unless @options[:include_version]
76
-
77
- # Multi-database support: Cache migration versions per database connection to handle
78
- # different schema versions across primary/secondary databases correctly.
79
- # Example: primary → "current_version_primary", secondary → "current_version_secondary"
80
- connection_pool_name = model.connection.pool.db_config.name
81
- cache_key = "current_version_#{connection_pool_name}".to_sym
82
-
83
- if @options.get_state(cache_key).nil?
84
- migration_version = begin
85
- model.connection.migration_context.current_version
86
- rescue
87
- 0
88
- end
89
-
90
- @options.set_state(cache_key, migration_version)
91
- end
92
-
93
- @options.get_state(cache_key)
94
- end
95
71
  end
96
72
  end
97
73
  end
@@ -16,17 +16,26 @@ module AnnotateRb
16
16
 
17
17
  begin
18
18
  klass = ModelClassGetter.call(@file, @options)
19
- return false unless klass.respond_to?(:descends_from_active_record?) && klass.descends_from_active_record? && klass.table_exists?
20
19
 
21
- return @options[:exclude_sti_subclasses] ? klass.base_class? : true
20
+ return false unless klass.respond_to?(:descends_from_active_record?)
21
+
22
+ # Skip annotating STI classes
23
+ if @options[:exclude_sti_subclasses] && !klass.descends_from_active_record?
24
+ return false
25
+ end
26
+
27
+ return false if klass.abstract_class?
28
+ return false unless klass.table_exists?
29
+
30
+ return true
22
31
  rescue BadModelFileError => e
23
32
  unless @options[:ignore_unknown_models]
24
33
  warn "Unable to process #{@file}: #{e.message}"
25
- warn "\t" + e.backtrace.join("\n\t") if @options[:trace]
34
+ warn "\t#{e.backtrace.join("\n\t")}" if @options[:trace]
26
35
  end
27
36
  rescue => e
28
37
  warn "Unable to process #{@file}: #{e.message}"
29
- warn "\t" + e.backtrace.join("\n\t") if @options[:trace]
38
+ warn "\t#{e.backtrace.join("\n\t")}" if @options[:trace]
30
39
  end
31
40
 
32
41
  false
@@ -32,9 +32,8 @@ module AnnotateRb
32
32
  warn "Either specify models on the command line, or use the --model-dir option."
33
33
  warn "Call 'annotaterb --help' for more info."
34
34
  # exit 1 # TODO: Return exit code back to caller. Right now it messes up RSpec being able to run
35
- else
36
- model_files
37
35
  end
36
+ model_files
38
37
  end
39
38
 
40
39
  private
@@ -221,6 +221,28 @@ module AnnotateRb
221
221
  @klass.name.foreign_key.to_sym
222
222
  ]
223
223
  end
224
+
225
+ def migration_version
226
+ return 0 unless @options[:include_version]
227
+
228
+ # Multi-database support: Cache migration versions per database connection to handle
229
+ # different schema versions across primary/secondary databases correctly.
230
+ # Example: primary → "current_version_primary", secondary → "current_version_secondary"
231
+ connection_pool_name = connection.pool.db_config.name
232
+ cache_key = "current_version_#{connection_pool_name}".to_sym
233
+
234
+ if @options.get_state(cache_key).nil?
235
+ migration_version = begin
236
+ connection.migration_context.current_version
237
+ rescue
238
+ 0
239
+ end
240
+
241
+ @options.set_state(cache_key, migration_version)
242
+ end
243
+
244
+ @options.get_state(cache_key)
245
+ end
224
246
  end
225
247
  end
226
248
  end
@@ -423,9 +423,9 @@ module AnnotateRb
423
423
  end
424
424
 
425
425
  option_parser.on("-e",
426
- "--exclude [tests,fixtures,factories,serializers]",
426
+ "--exclude [tests,fixtures,factories,serializers,sti_subclasses]",
427
427
  Array,
428
- "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
428
+ "Do not annotate fixtures, test files, factories, serializers, and/or sti subclasses") do |exclusions|
429
429
  exclusions ||= EXCLUSION_LIST
430
430
  exclusions.each { |exclusion| @options["exclude_#{exclusion}".to_sym] = true }
431
431
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.18.0
4
+ version: 4.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew W. Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-04 00:00:00.000000000 Z
11
+ date: 2025-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord