annotaterb 4.15.0 → 4.16.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: a31463c338bd23299c7249e3c444d8c1b630157bf9905cfeb203dfafb1a4d16a
4
- data.tar.gz: ad12fccdeeb0186d6627ba237c417c637b1b6136f354313e81f09de90cef4665
3
+ metadata.gz: 91c5e0b20f8c7f5a3160bd2eac0f1e96f9b05e9fd72ddd08fc18422d63472510
4
+ data.tar.gz: e7bfda05d5943c0b2c978dc6863151aad9c1934b6ff5551ec88292ab96dfc57d
5
5
  SHA512:
6
- metadata.gz: af6ec6a16d36b65b00eb28f4736c46682aa0d47da4869503eaecb8a58a8ff34f783ac3986c09200f125279666a8b30658af1ba91a9ad5829d789846c1c9e82dd
7
- data.tar.gz: ad7fbd08360072a24c2fbea2808c180806ae89da5775689d1f7cc2824fead770b771ac41667056e68da0921ae13948a6f3da48883ab2f0328506cbf7158a63c0
6
+ metadata.gz: 42f9849dd393c04606dcbd7ada4749bfb617180fe3992d19adb16f17f00a9e4af4ecae34d2a9305b5a2ab5b359c4762a87c83cd43c395302e14387b43538ccb2
7
+ data.tar.gz: 5cc6acd44ac8ae6c4aeb5895e776adf3ac75044fc67e4c2682527256bda5a36915670dbae92e3a478f55d883907c5c480e28c769b7f40c219c5d4a06fc64750f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.15.0](https://github.com/drwl/annotaterb/tree/v4.15.0) (2025-05-30)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.14.1...v4.15.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - Feature request: packs-rails support [\#99](https://github.com/drwl/annotaterb/issues/99)
10
+ - Annotate models using Zeitwerk namespaces [\#82](https://github.com/drwl/annotaterb/issues/82)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Bump version to v4.15.0 [\#218](https://github.com/drwl/annotaterb/pull/218) ([drwl](https://github.com/drwl))
15
+ - Add debug logs for model annotation [\#217](https://github.com/drwl/annotaterb/pull/217) ([jarredhawkins](https://github.com/jarredhawkins))
16
+ - Cache retrieved indexes in ModelWrapper [\#215](https://github.com/drwl/annotaterb/pull/215) ([tr4b4nt](https://github.com/tr4b4nt))
17
+ - feat: identify unique indexes in simple\_indexes option [\#214](https://github.com/drwl/annotaterb/pull/214) ([amerritt14](https://github.com/amerritt14))
18
+ - fix: Handle case when table\_name\_prefix specified as symbol [\#208](https://github.com/drwl/annotaterb/pull/208) ([gururuby](https://github.com/gururuby))
19
+ - Support the glob pattern in `root_dir` and `model_dir` [\#198](https://github.com/drwl/annotaterb/pull/198) ([sinsoku](https://github.com/sinsoku))
20
+ - Fix `changelog_uri` in gemspec [\#192](https://github.com/drwl/annotaterb/pull/192) ([y-yagi](https://github.com/y-yagi))
21
+ - Generate changelog for v4.14.0 [\#191](https://github.com/drwl/annotaterb/pull/191) ([drwl](https://github.com/drwl))
22
+ - feat: add `timestamp_columns` config option [\#173](https://github.com/drwl/annotaterb/pull/173) ([pbernays](https://github.com/pbernays))
23
+
24
+ ## [v4.14.1](https://github.com/drwl/annotaterb/tree/v4.14.1) (2025-03-31)
25
+
26
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.14.0...v4.14.1)
27
+
28
+ **Closed issues:**
29
+
30
+ - Sort by database order [\#194](https://github.com/drwl/annotaterb/issues/194)
31
+ - “wrong number of arguments \(given 0, expected 1..2\)” when using enum in a Rails 8 model [\#184](https://github.com/drwl/annotaterb/issues/184)
32
+
3
33
  ## [v4.14.0](https://github.com/drwl/annotaterb/tree/v4.14.0) (2025-02-17)
4
34
 
5
35
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.13.0...v4.14.0)
data/README.md CHANGED
@@ -134,6 +134,7 @@ Annotate model options:
134
134
  --ignore-unknown-models don't display warnings for bad model files
135
135
  -I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`
136
136
  --with-comment include database comments in model annotations
137
+ --with-column-comments include column comments in model annotations
137
138
 
138
139
  Annotate routes options:
139
140
  Usage: annotaterb routes [options]
@@ -149,7 +150,7 @@ Command options:
149
150
  Additional options that work for annotating models and routes
150
151
 
151
152
  --additional-file-patterns path1,path2,path3
152
- Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
153
+ Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%MODEL_NAME%/*.rb,/baz/%MODEL_NAME%.rb`)
153
154
  -d, --delete Remove annotations from all model files or the routes.rb file
154
155
  --model-dir dir Annotate model files stored in dir rather than app/models, separate multiple dirs with commas
155
156
  --root-dir dir Annotate files stored within root dir projects, separate multiple dirs with commas
@@ -192,7 +193,7 @@ Previously in the [Annotate](https://github.com/ctran/annotate_models) you could
192
193
  position: after
193
194
  ```
194
195
 
195
- Annotaterb reads first from the configuration file, if it exists, then merges it with any options passed into the CLI.
196
+ Annotaterb reads first the configuration file, if it exists, passes its content through ERB, and merges the result with any options passed into the CLI.
196
197
 
197
198
  For further details visit the [section in the migration guide](MIGRATION_GUIDE.md#automatic-annotations-after-running-database-migration-commands).
198
199
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.15.0
1
+ 4.16.0
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "erb"
4
+
3
5
  module AnnotateRb
4
6
  # Raised when a configuration file is not found.
5
7
  class ConfigNotFoundError < StandardError
@@ -20,8 +22,9 @@ module AnnotateRb
20
22
  # Method from Rubocop::ConfigLoader
21
23
  def load_yaml_configuration(absolute_path)
22
24
  file_contents = read_file(absolute_path)
25
+ yaml_code = ERB.new(file_contents).result
23
26
 
24
- hash = yaml_safe_load(file_contents, absolute_path) || {}
27
+ hash = yaml_safe_load(yaml_code, absolute_path) || {}
25
28
 
26
29
  # TODO: Print config if debug flag/option is set
27
30
 
@@ -47,19 +47,46 @@ module AnnotateRb
47
47
  def content_annotated_before(parsed, content_without_annotations, write_position)
48
48
  same_write_position = @parsed_file.has_annotations? && @parsed_file.annotation_position.to_s == write_position
49
49
 
50
- # Could error if there's no class or module declaration
51
- _constant_name, line_number_before = parsed.starts.first
50
+ _constant_name, line_number_before = determine_annotation_position(parsed)
52
51
 
53
52
  content_with_annotations_written_before = []
54
53
  content_with_annotations_written_before << content_without_annotations.lines[0...line_number_before]
55
54
  content_with_annotations_written_before << $/ if @parsed_file.has_leading_whitespace? && same_write_position
56
- content_with_annotations_written_before << @new_wrapped_annotations.lines
55
+ content_with_annotations_written_before << formatted_annotations(content_without_annotations, line_number_before)
57
56
  content_with_annotations_written_before << $/ if @parsed_file.has_trailing_whitespace? && same_write_position
58
57
  content_with_annotations_written_before << content_without_annotations.lines[line_number_before..]
59
58
 
60
59
  content_with_annotations_written_before.join
61
60
  end
62
61
 
62
+ # Determines where to place the annotation based on the nested_position option.
63
+ # When nested_position is enabled, finds the most deeply nested class declaration
64
+ # to place annotations directly above nested classes instead of at the file top.
65
+ def determine_annotation_position(parsed)
66
+ return parsed.starts.first unless @options[:nested_position]
67
+
68
+ class_entries = parsed.starts.select { |name, _line| parsed.type_map[name] == :class }
69
+ class_entries.last || parsed.starts.first
70
+ end
71
+
72
+ # Formats annotations with appropriate indentation for consistent code structure.
73
+ # Applies the same indentation level as the target line to maintain proper
74
+ # code alignment when using nested positioning.
75
+ def formatted_annotations(content_without_annotations, line_number_before)
76
+ indentation = determine_indentation(content_without_annotations, line_number_before)
77
+ @new_wrapped_annotations.lines.map { |line| "#{indentation}#{line}" }
78
+ end
79
+
80
+ # Calculates the indentation string to apply to annotations for nested positioning.
81
+ # Extracts leading whitespace from the target line to preserve visual hierarchy
82
+ # and readability of nested code structures.
83
+ def determine_indentation(content_without_annotations, line_number_before)
84
+ return "" unless @options[:nested_position] && line_number_before > 0
85
+
86
+ target_line = content_without_annotations.lines[line_number_before]
87
+ target_line&.match(/^(\s*)/)&.[](1) || ""
88
+ end
89
+
63
90
  def content_annotated_after(parsed, content_without_annotations)
64
91
  _constant_name, line_number_after = parsed.ends.last
65
92
 
@@ -264,6 +264,11 @@ module AnnotateRb
264
264
  [klass]
265
265
  end
266
266
  end
267
+
268
+ option_parser.on("--nested-position",
269
+ "Place annotations directly above nested classes or modules instead of at the top of the file.") do
270
+ @options[:nested_position] = true
271
+ end
267
272
  end
268
273
 
269
274
  def add_route_options_to_parser(option_parser)
@@ -362,7 +367,7 @@ module AnnotateRb
362
367
 
363
368
  option_parser.on("--additional-file-patterns path1,path2,path3",
364
369
  Array,
365
- "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns|
370
+ "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%MODEL_NAME%/*.rb,/baz/%MODEL_NAME%.rb`)") do |additional_file_patterns|
366
371
  @options[:additional_file_patterns] = additional_file_patterns
367
372
  end
368
373
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.15.0
4
+ version: 4.16.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-05-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 6.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 6.0.0
13
41
  description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
14
42
  on the database schema.
15
43
  email:
@@ -131,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
159
  requirements:
132
160
  - - ">="
133
161
  - !ruby/object:Gem::Version
134
- version: 2.7.0
162
+ version: 3.0.0
135
163
  required_rubygems_version: !ruby/object:Gem::Requirement
136
164
  requirements:
137
165
  - - ">="