annotaterb 4.20.0 → 4.22.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: 9df7cea27e60968dc415cd65fc55696bfcb47444bdb0dc9964ce155bfbce4e40
4
- data.tar.gz: 6883710db1dd58633c3a349adec97257df9c2d809a220fd19ba90c2a4a584cb7
3
+ metadata.gz: 2be17a236402d5406e2f4d1f68a567bf51de51f924f66591adf9460bfacabe18
4
+ data.tar.gz: 48743c136f9a195bb1dbaa564bd8047c16411394a991b4c86b57a70844d0e121
5
5
  SHA512:
6
- metadata.gz: 2e164027db851243b7a1fccf9590c4a7515f47454ec785070e8e1dcd71bc0de7bec2caea30d919e6497dedfe78180681828cd6f1e24c6f0539c1d4e6b7895c33
7
- data.tar.gz: 65629d818e0f3a92528deec50d5ba6adeb4a521058a174a7d463df1d565a8bf59eccd4ddb039ea68fe0dffed7329a994a5fbc1dae9cf19cb87cf9dcec7e308f2
6
+ metadata.gz: a203a269dbcf4c42a082a2088c6c38d8c4b97c3bbf9ab760762e3149294fb38dc31799aea2f3ece425504782cd2027187bd161ccf4a9c006aaa7a9a791094311
7
+ data.tar.gz: 8cc55f09f193f5f428db97afc1270386a06eb8185773cfd339830e1ee8e49631a1f203cced676fdb2f4d7d5c0b690f5aadc9108f63d3de588c019d7585c0011b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.21.0](https://github.com/drwl/annotaterb/tree/v4.21.0) (2026-01-30)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.20.0...v4.21.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Displaying database name for multi-database rails projects [\#254](https://github.com/drwl/annotaterb/issues/254)
10
+
11
+ **Fixed bugs:**
12
+
13
+ - Yard format broken? [\#212](https://github.com/drwl/annotaterb/issues/212)
14
+
15
+ **Closed issues:**
16
+
17
+ - \[dotenv\] Loaded comment gets added to routes annotations [\#288](https://github.com/drwl/annotaterb/issues/288)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Bump version to v4.21.0 [\#306](https://github.com/drwl/annotaterb/pull/306) ([drwl](https://github.com/drwl))
22
+ - Add integration test for ignore\_multi\_database\_name config option [\#305](https://github.com/drwl/annotaterb/pull/305) ([OdenTakashi](https://github.com/OdenTakashi))
23
+ - Include ignore\_multi\_database\_name in generated config [\#304](https://github.com/drwl/annotaterb/pull/304) ([OdenTakashi](https://github.com/OdenTakashi))
24
+ - Add to\_yard and to\_rdoc methods to Annotation classes [\#302](https://github.com/drwl/annotaterb/pull/302) ([k-duho](https://github.com/k-duho))
25
+ - Support customising config path [\#301](https://github.com/drwl/annotaterb/pull/301) ([rience](https://github.com/rience))
26
+ - Bump actions/checkout from 5 to 6 [\#299](https://github.com/drwl/annotaterb/pull/299) ([dependabot[bot]](https://github.com/apps/dependabot))
27
+ - Update Rails generator command in README [\#296](https://github.com/drwl/annotaterb/pull/296) ([EstebanDalelR](https://github.com/EstebanDalelR))
28
+ - chore: remove concurrent-ruby version lock from dummy app [\#284](https://github.com/drwl/annotaterb/pull/284) ([OdenTakashi](https://github.com/OdenTakashi))
29
+ - feat: Add "ignore\_multi\_database\_name" option [\#283](https://github.com/drwl/annotaterb/pull/283) ([t27duck](https://github.com/t27duck))
30
+ - refactor: use existing `database_name` method for cache key [\#282](https://github.com/drwl/annotaterb/pull/282) ([OdenTakashi](https://github.com/OdenTakashi))
31
+ - Support .config directory convention [\#281](https://github.com/drwl/annotaterb/pull/281) ([ngan](https://github.com/ngan))
32
+ - chore: add missing newlines [\#280](https://github.com/drwl/annotaterb/pull/280) ([OdenTakashi](https://github.com/OdenTakashi))
33
+ - Generate changelog for v4.20.0 [\#279](https://github.com/drwl/annotaterb/pull/279) ([drwl](https://github.com/drwl))
34
+
35
+ ## [v4.20.0](https://github.com/drwl/annotaterb/tree/v4.20.0) (2025-10-20)
36
+
37
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.19.0...v4.20.0)
38
+
39
+ **Merged pull requests:**
40
+
41
+ - Bump version to v4.20.0 [\#278](https://github.com/drwl/annotaterb/pull/278) ([drwl](https://github.com/drwl))
42
+ - Bump github/codeql-action from 3 to 4 [\#277](https://github.com/drwl/annotaterb/pull/277) ([dependabot[bot]](https://github.com/apps/dependabot))
43
+ - fix: position-of-column-comment option [\#275](https://github.com/drwl/annotaterb/pull/275) ([JohnnyKei](https://github.com/JohnnyKei))
44
+ - feat: Add database name to annotations in multi-DB environments [\#272](https://github.com/drwl/annotaterb/pull/272) ([OdenTakashi](https://github.com/OdenTakashi))
45
+ - fix: resolve YAML syntax error in update\_config generator [\#269](https://github.com/drwl/annotaterb/pull/269) ([ivy](https://github.com/ivy))
46
+ - Update README.md [\#268](https://github.com/drwl/annotaterb/pull/268) ([torgoton](https://github.com/torgoton))
47
+ - Honor --frozen option in routes [\#265](https://github.com/drwl/annotaterb/pull/265) ([garriguv](https://github.com/garriguv))
48
+ - refactor\(test\): Default to single-DB environment for tests [\#264](https://github.com/drwl/annotaterb/pull/264) ([OdenTakashi](https://github.com/OdenTakashi))
49
+ - Escape column comment newlines when using "rightmost" value for position\_of\_column\_comment option [\#263](https://github.com/drwl/annotaterb/pull/263) ([rowanhogan](https://github.com/rowanhogan))
50
+ - chore: introduce switchable DB environment for specs [\#262](https://github.com/drwl/annotaterb/pull/262) ([OdenTakashi](https://github.com/OdenTakashi))
51
+ - Generate changelog for v4.19.0 [\#260](https://github.com/drwl/annotaterb/pull/260) ([drwl](https://github.com/drwl))
52
+ - Bump actions/checkout from 4 to 5 [\#257](https://github.com/drwl/annotaterb/pull/257) ([dependabot[bot]](https://github.com/apps/dependabot))
53
+
3
54
  ## [v4.19.0](https://github.com/drwl/annotaterb/tree/v4.19.0) (2025-08-28)
4
55
 
5
56
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.18.0...v4.19.0)
data/README.md CHANGED
@@ -75,7 +75,7 @@ $ ANNOTATERB_SKIP_ON_DB_TASKS=1 bin/rails db:migrate
75
75
  The following Rails generator commands get added.
76
76
 
77
77
  ```sh
78
- $ bin/rails generator --help
78
+ $ bin/rails generate --help
79
79
 
80
80
  ...
81
81
 
@@ -183,6 +183,7 @@ Additional options that work for annotating models and routes
183
183
  --exclude Do not annotate fixtures, test files, factories, and/or serializers
184
184
  -f [bare|rdoc|yard|markdown], Render Schema Information as plain/RDoc/Yard/Markdown
185
185
  --format
186
+ --config_path [path] Path to configuration file (by default, .annotaterb.yml in the root of the project)
186
187
  -p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
187
188
  --position
188
189
  --pc, --position-in-class [before|top|after|bottom]
@@ -211,6 +212,14 @@ Additional options that work for annotating models and routes
211
212
 
212
213
  Previously in the [Annotate](https://github.com/ctran/annotate_models) you could pass options through the CLI or store them as environment variables. Annotaterb removes dependency on the environment variables and instead can read values from a `.annotaterb.yml` file stored in the Rails project root.
213
214
 
215
+ ### Configuration file location
216
+
217
+ AnnotateRb also supports other configuration file locations, and are searched for in the following locations (in order of precedence):
218
+ - `.annotaterb.yml`
219
+ - `config/annotaterb.yml`
220
+ - `.config/.annotaterb.yml`
221
+ - `.config/annotaterb/config.yml`
222
+
214
223
  ```yml
215
224
  # .annotaterb.yml
216
225
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.0
1
+ 4.22.0
@@ -1,20 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+
3
5
  module AnnotateRb
4
6
  class ConfigFinder
5
7
  DOTFILE = ".annotaterb.yml"
6
8
 
7
9
  class << self
10
+ attr_accessor :config_path
11
+
8
12
  def find_project_root
9
13
  # We should expect this method to be called from a Rails project root and returning it
10
14
  # e.g. "/Users/drwl/personal/annotaterb/dummyapp"
11
- Dir.pwd
15
+ Pathname.pwd
12
16
  end
13
17
 
14
18
  def find_project_dotfile
15
- file_path = File.expand_path(DOTFILE, find_project_root)
19
+ return @config_path if @config_path && File.exist?(@config_path)
16
20
 
17
- return file_path if File.exist?(file_path)
21
+ [
22
+ find_project_root.join(DOTFILE),
23
+ find_project_root.join("config", DOTFILE.delete_prefix(".")),
24
+ find_project_root.join(".config", DOTFILE),
25
+ find_project_root.join(".config", "annotaterb", "config.yml")
26
+ ].find(&:exist?)
18
27
  end
19
28
  end
20
29
  end
@@ -66,7 +66,7 @@ module AnnotateRb
66
66
  # Handle empty files where no classes/modules are found
67
67
  return [nil, 0] if parsed.starts.empty?
68
68
 
69
- return parsed.starts.first unless @options[:nested_position]
69
+ return parsed.starts.first unless @options[:nested_position] && parsed.respond_to?(:type_map)
70
70
 
71
71
  class_entries = parsed.starts.select { |name, _line| parsed.type_map[name] == :class }
72
72
  class_entries.last || parsed.starts.first
@@ -74,6 +74,8 @@ module AnnotateRb
74
74
  private
75
75
 
76
76
  def multi_db_environment?
77
+ return false if @options[:ignore_multi_database_name]
78
+
77
79
  if defined?(::Rails) && ::Rails.env
78
80
  ActiveRecord::Base.configurations.configs_for(env_name: ::Rails.env).size > 1
79
81
  else
@@ -31,13 +31,13 @@ module AnnotateRb
31
31
  new_annotations = @annotation_block.match(HEADER_PATTERN).to_s
32
32
 
33
33
  current_annotation_columns = if current_annotations.present?
34
- current_annotations.scan(COLUMN_PATTERN).sort
34
+ current_annotations.scan(COLUMN_PATTERN)
35
35
  else
36
36
  []
37
37
  end
38
38
 
39
39
  new_annotation_columns = if new_annotations.present?
40
- new_annotations.scan(COLUMN_PATTERN).sort
40
+ new_annotations.scan(COLUMN_PATTERN)
41
41
  else
42
42
  []
43
43
  end
@@ -23,6 +23,14 @@ module AnnotateRb
23
23
  body.map(&:to_markdown).join("\n")
24
24
  end
25
25
 
26
+ def to_rdoc
27
+ body.map(&:to_rdoc).join("\n")
28
+ end
29
+
30
+ def to_yard
31
+ body.map(&:to_yard).join("\n")
32
+ end
33
+
26
34
  def to_default
27
35
  body.map(&:to_default).join("\n")
28
36
  end
@@ -23,6 +23,14 @@ module AnnotateRb
23
23
  body.map(&:to_markdown).join("\n")
24
24
  end
25
25
 
26
+ def to_rdoc
27
+ body.map(&:to_rdoc).join("\n")
28
+ end
29
+
30
+ def to_yard
31
+ body.map(&:to_yard).join("\n")
32
+ end
33
+
26
34
  def to_default
27
35
  body.map(&:to_default).join("\n")
28
36
  end
@@ -23,6 +23,14 @@ module AnnotateRb
23
23
  body.map(&:to_markdown).join("\n")
24
24
  end
25
25
 
26
+ def to_rdoc
27
+ body.map(&:to_rdoc).join("\n")
28
+ end
29
+
30
+ def to_yard
31
+ body.map(&:to_yard).join("\n")
32
+ end
33
+
26
34
  def to_default
27
35
  body.map(&:to_default).join("\n")
28
36
  end
@@ -35,7 +35,11 @@ module AnnotateRb
35
35
  end
36
36
 
37
37
  def connection
38
- @klass.connection
38
+ if @klass.respond_to?(:lease_connection)
39
+ @klass.lease_connection
40
+ else
41
+ @klass.connection
42
+ end
39
43
  end
40
44
 
41
45
  def database_name
@@ -56,12 +60,12 @@ module AnnotateRb
56
60
  end
57
61
 
58
62
  def table_comments
59
- @klass.connection.table_comment(@klass.table_name)
63
+ connection.table_comment(@klass.table_name)
60
64
  end
61
65
 
62
66
  def has_table_comments?
63
- @klass.connection.respond_to?(:table_comment) &&
64
- @klass.connection.table_comment(@klass.table_name).present?
67
+ connection.respond_to?(:table_comment) &&
68
+ connection.table_comment(@klass.table_name).present?
65
69
  end
66
70
 
67
71
  def column_defaults
@@ -113,21 +117,10 @@ module AnnotateRb
113
117
  end
114
118
  end
115
119
 
116
- # TODO: Simplify this conditional
117
120
  def is_column_primary_key?(column_name)
118
- if primary_key
119
- if primary_key.is_a?(Array)
120
- # If the model has multiple primary keys, check if this column is one of them
121
- if primary_key.collect(&:to_sym).include?(column_name.to_sym)
122
- return true
123
- end
124
- elsif column_name.to_sym == primary_key.to_sym
125
- # If model has 1 primary key, check if this column is it
126
- return true
127
- end
128
- end
121
+ return false unless primary_key
129
122
 
130
- false
123
+ Array(primary_key).map(&:to_sym).include?(column_name.to_sym)
131
124
  end
132
125
 
133
126
  def built_attributes
@@ -150,13 +143,13 @@ module AnnotateRb
150
143
  table_name = @klass.table_name
151
144
  return [] unless table_name
152
145
 
153
- indexes = @klass.connection.indexes(table_name)
146
+ indexes = connection.indexes(table_name)
154
147
  return indexes if indexes.any? || !@klass.table_name_prefix
155
148
 
156
149
  # Try to search the table without prefix
157
150
  table_name_without_prefix = table_name.to_s.sub(@klass.table_name_prefix.to_s, "")
158
151
  begin
159
- @klass.connection.indexes(table_name_without_prefix)
152
+ connection.indexes(table_name_without_prefix)
160
153
  rescue ActiveRecord::StatementInvalid => _e
161
154
  # Mysql2 adapter behaves differently than Sqlite3 and Postgres adapter.
162
155
  # If `table_name_without_prefix` does not exist, Mysql2 will raise,
@@ -232,8 +225,7 @@ module AnnotateRb
232
225
  # Multi-database support: Cache migration versions per database connection to handle
233
226
  # different schema versions across primary/secondary databases correctly.
234
227
  # Example: primary → "current_version_primary", secondary → "current_version_secondary"
235
- connection_pool_name = connection.pool.db_config.name
236
- cache_key = "current_version_#{connection_pool_name}".to_sym
228
+ cache_key = "current_version_#{database_name}".to_sym
237
229
 
238
230
  if @options.get_state(cache_key).nil?
239
231
  migration_version = begin
@@ -76,6 +76,7 @@ module AnnotateRb
76
76
  timestamp_columns: ModelAnnotator::ModelWrapper::DEFAULT_TIMESTAMP_COLUMNS,
77
77
 
78
78
  ignore_columns: nil, # ModelAnnotator
79
+ ignore_multi_database_name: false, # ModelAnnotator
79
80
  ignore_routes: nil, # RouteAnnotator
80
81
  ignore_unknown_models: false, # ModelAnnotator
81
82
  models: true, # Core
@@ -143,6 +144,7 @@ module AnnotateRb
143
144
  :ignore_columns,
144
145
  :ignore_routes,
145
146
  :ignore_unknown_models,
147
+ :ignore_multi_database_name,
146
148
  :models,
147
149
  :routes,
148
150
  :skip_on_db_migrate,
@@ -436,6 +436,11 @@ module AnnotateRb
436
436
  "Render Schema Information as plain/RDoc/Yard/Markdown") do |format_type|
437
437
  @options["format_#{format_type}".to_sym] = true
438
438
  end
439
+
440
+ option_parser.on("--config-path [path]",
441
+ "Path to configuration file (by default, .annotaterb.yml in the root of the project)") do |path|
442
+ @options[:config_path] = path
443
+ end
439
444
  end
440
445
  end
441
446
  end
@@ -3,8 +3,9 @@
3
3
  module AnnotateRb
4
4
  class RakeBootstrapper
5
5
  class << self
6
- def call(options)
6
+ def call
7
7
  require "rake"
8
+
8
9
  load "./Rakefile" if File.exist?("./Rakefile") && !Rake::Task.task_defined?(:environment)
9
10
 
10
11
  begin
@@ -23,23 +23,23 @@ module AnnotateRb
23
23
  end
24
24
 
25
25
  def run(args)
26
- config_file_options = ConfigLoader.load_config
27
26
  parser = Parser.new(args, {})
28
27
 
29
28
  parsed_options = parser.parse
30
29
  remaining_args = parser.remaining_args
31
30
 
31
+ AnnotateRb::ConfigFinder.config_path = parsed_options[:config_path] if parsed_options[:config_path]
32
+ config_file_options = ConfigLoader.load_config
32
33
  options = config_file_options.merge(parsed_options)
33
34
 
34
35
  @options = Options.from(options, {working_args: remaining_args})
35
- AnnotateRb::RakeBootstrapper.call(@options)
36
+ AnnotateRb::RakeBootstrapper.call
36
37
 
37
- if @options[:command]
38
- @options[:command].call(@options)
39
- else
40
- # TODO
41
- raise "Didn't specify a command"
42
- end
38
+ raise "Didn't specify a command" unless @options[:command]
39
+
40
+ @options[:command].call(@options)
41
+
42
+ # TODO
43
43
  end
44
44
  end
45
45
  end
@@ -22,8 +22,11 @@ if defined?(Rails::Application) && Rails.version.split(".").first.to_i >= 6
22
22
  end
23
23
  end
24
24
 
25
+ config = ::AnnotateRb::ConfigLoader.load_config
26
+
25
27
  migration_tasks.each do |task|
26
28
  next unless Rake::Task.task_defined?(task)
29
+ next if config[:skip_on_db_migrate]
27
30
 
28
31
  Rake::Task[task].enhance do # This block is ran after `task` completes
29
32
  task_name = Rake.application.top_level_tasks.last # The name of the task that was run, e.g. "db:migrate"
data/lib/annotate_rb.rb CHANGED
@@ -2,14 +2,11 @@
2
2
 
3
3
  require "active_record"
4
4
  require "active_support"
5
-
6
- # Helper.fallback depends on this being required because it adds #present? to nil
7
- require "active_support/core_ext/object/blank"
8
- require "active_support/core_ext/class/subclasses"
9
- require "active_support/core_ext/string/inflections"
10
-
11
5
  require "rake"
12
6
 
7
+ module AnnotateRb
8
+ end
9
+
13
10
  require_relative "annotate_rb/helper"
14
11
  require_relative "annotate_rb/core"
15
12
  require_relative "annotate_rb/commands"
@@ -23,6 +20,3 @@ require_relative "annotate_rb/rake_bootstrapper"
23
20
  require_relative "annotate_rb/config_finder"
24
21
  require_relative "annotate_rb/config_loader"
25
22
  require_relative "annotate_rb/config_generator"
26
-
27
- module AnnotateRb
28
- end
data/lib/annotaterb.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Gem names that follow naming convention work seamlessly. However, this gem is "annotaterb" where in code it is
2
2
  # AnnotateRb. Because of this, we need this file so that the rest of the library automatically gets required.
3
3
 
4
- require "annotate_rb"
4
+ require_relative "annotate_rb"
@@ -4,5 +4,7 @@
4
4
  if Rails.env.development? && ENV["ANNOTATERB_SKIP_ON_DB_TASKS"].nil?
5
5
  require "annotate_rb"
6
6
 
7
+ # Can modify the config path here if needed - by default, it's .annotaterb.yml in the root of the project
8
+ # AnnotateRb::ConfigFinder.config_path = ""
7
9
  AnnotateRb::Core.load_rake_tasks
8
10
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.0
4
+ version: 4.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew W. Lee
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-10-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -151,7 +150,6 @@ metadata:
151
150
  changelog_uri: https://github.com/drwl/annotaterb/blob/main/CHANGELOG.md
152
151
  bug_tracker_uri: https://github.com/drwl/annotaterb/issues
153
152
  rubygems_mfa_required: 'true'
154
- post_install_message:
155
153
  rdoc_options: []
156
154
  require_paths:
157
155
  - lib
@@ -166,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
164
  - !ruby/object:Gem::Version
167
165
  version: '0'
168
166
  requirements: []
169
- rubygems_version: 3.5.22
170
- signing_key:
167
+ rubygems_version: 4.0.4
171
168
  specification_version: 4
172
169
  summary: A gem for generating annotations for Rails projects.
173
170
  test_files: []