annotaterb 4.25.0 → 4.26.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 +4 -4
- data/CHANGELOG.md +33 -1
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/annotate_rb/model_annotator/file_name_resolver.rb +1 -1
- data/lib/annotate_rb/model_annotator/model_class_getter.rb +3 -1
- data/lib/annotate_rb/model_annotator/model_wrapper.rb +29 -3
- data/lib/annotate_rb/model_annotator/related_files_list_builder.rb +11 -1
- data/lib/annotate_rb/model_annotator/single_file_annotator.rb +12 -0
- data/lib/annotate_rb/options.rb +2 -0
- data/lib/annotate_rb/parser.rb +5 -0
- data/lib/annotate_rb/rake_bootstrapper.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 128081f8778da0dda7fc1f5ea0a24544900e92ec1a2300a1baf1429dcc52946b
|
|
4
|
+
data.tar.gz: d093aba69c6949247182263968b2d9a63ee8be1c34dc2b473819c9e7cef73ef2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1581a93b0b0c29054b3ceb8d30a581834d809134a8ed8c546c2b285fb90f505c8c5dca99e7cb2449c3bd87dc60c3b756f033229672a721941c1d599b94d62adc
|
|
7
|
+
data.tar.gz: 8368a6349d5070d09aa9967a3474d92140fce7427c32b4273aad70aa2ca3e39486464bd6be4aff2560f7505b1aaf3de4980a533002aa5c82f0dcbeeeffff3555
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v4.25.0](https://github.com/drwl/annotaterb/tree/v4.25.0) (2026-09-17)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.24.0...v4.25.0)
|
|
6
|
+
|
|
7
|
+
**Fixed bugs:**
|
|
8
|
+
|
|
9
|
+
- Missing unique indexes in annotations [\#390](https://github.com/drwl/annotaterb/issues/390)
|
|
10
|
+
- Related files are matched globally by unqualified model name, so models with the same basename in different packs overwrite each other's annotations \(breaks --frozen\) [\#367](https://github.com/drwl/annotaterb/issues/367)
|
|
11
|
+
- When `format_markdown: true`, annotations get written duplicated into models that already have annotations. [\#355](https://github.com/drwl/annotaterb/issues/355)
|
|
12
|
+
|
|
13
|
+
**Closed issues:**
|
|
14
|
+
|
|
15
|
+
- Foreign-key annotation crashes with ArgumentError when unnamed FKs mix with a composite FK [\#377](https://github.com/drwl/annotaterb/issues/377)
|
|
16
|
+
- 4.24.0: enum-backed integer columns annotate raw default\(0\) instead of default\("label"\) [\#373](https://github.com/drwl/annotaterb/issues/373)
|
|
17
|
+
|
|
18
|
+
**Merged pull requests:**
|
|
19
|
+
|
|
20
|
+
- Release v4.25.0 [\#395](https://github.com/drwl/annotaterb/pull/395) ([drwl](https://github.com/drwl))
|
|
21
|
+
- Bump github/codeql-action from 4.37.9 to 4.38.0 [\#394](https://github.com/drwl/annotaterb/pull/394) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
22
|
+
- Remove unused `routes` option [\#393](https://github.com/drwl/annotaterb/pull/393) ([OdenTakashi](https://github.com/OdenTakashi))
|
|
23
|
+
- Bump github/codeql-action from 4.37.4 to 4.37.9 [\#389](https://github.com/drwl/annotaterb/pull/389) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
24
|
+
- Use native prefix predicate in YAML parser [\#387](https://github.com/drwl/annotaterb/pull/387) ([OskarEichler](https://github.com/OskarEichler))
|
|
25
|
+
- Fix multi-database annotation removal fixture targeting [\#386](https://github.com/drwl/annotaterb/pull/386) ([OskarEichler](https://github.com/OskarEichler))
|
|
26
|
+
- Update annotated model in README [\#385](https://github.com/drwl/annotaterb/pull/385) ([koeda-ta](https://github.com/koeda-ta))
|
|
27
|
+
- Show index operator classes in annotations [\#382](https://github.com/drwl/annotaterb/pull/382) ([kamipo](https://github.com/kamipo))
|
|
28
|
+
- Fix enum-backed integer columns annotations [\#380](https://github.com/drwl/annotaterb/pull/380) ([dmke](https://github.com/dmke))
|
|
29
|
+
- Fix ArgumentError sorting unnamed foreign keys when one is composite [\#378](https://github.com/drwl/annotaterb/pull/378) ([6temes](https://github.com/6temes))
|
|
30
|
+
- Bump github/codeql-action from 4 to 4.37.4 [\#376](https://github.com/drwl/annotaterb/pull/376) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
31
|
+
- docs: fix mistake in changelog [\#375](https://github.com/drwl/annotaterb/pull/375) ([G-Rath](https://github.com/G-Rath))
|
|
32
|
+
- Stop same-named models in different packs from annotating each others related files by matching on owning root\_dir. [\#374](https://github.com/drwl/annotaterb/pull/374) ([OdenTakashi](https://github.com/OdenTakashi))
|
|
33
|
+
- Generate changelog for v4.24.0 [\#372](https://github.com/drwl/annotaterb/pull/372) ([drwl](https://github.com/drwl))
|
|
34
|
+
|
|
3
35
|
## [v4.24.0](https://github.com/drwl/annotaterb/tree/v4.24.0) (2026-07-24)
|
|
4
36
|
|
|
5
37
|
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.23.0...v4.24.0)
|
|
@@ -7,7 +39,7 @@
|
|
|
7
39
|
**Implemented enhancements:**
|
|
8
40
|
|
|
9
41
|
- Annotate postgres enums [\#309](https://github.com/drwl/annotaterb/issues/309)
|
|
10
|
-
- `--frozen` option returns a
|
|
42
|
+
- `--frozen` option returns a zero error code when database is inaccessible [\#240](https://github.com/drwl/annotaterb/issues/240)
|
|
11
43
|
- Add support for printing enum types [\#176](https://github.com/drwl/annotaterb/issues/176)
|
|
12
44
|
|
|
13
45
|
**Fixed bugs:**
|
data/README.md
CHANGED
|
@@ -165,6 +165,7 @@ Annotate model options:
|
|
|
165
165
|
--without-table-comments exclude table comments in model annotations
|
|
166
166
|
--classes-default-to-s class Custom classes to be represented with `to_s`, may be used multiple times
|
|
167
167
|
--nested-position Place annotations directly above nested classes or modules instead of at the top of the file.
|
|
168
|
+
--load-columns-from-schema Load columns from schema to avoid ActiveRecord ignored/only column configuration
|
|
168
169
|
|
|
169
170
|
Annotate routes options:
|
|
170
171
|
Usage: annotaterb routes [options]
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.
|
|
1
|
+
4.26.0
|
|
@@ -13,7 +13,7 @@ module AnnotateRb
|
|
|
13
13
|
.gsub("%MODEL_NAME%", model_name)
|
|
14
14
|
.gsub("%MODEL_NAME_WITHOUT_NS%", model_name_without_namespace)
|
|
15
15
|
.gsub("%PLURALIZED_MODEL_NAME%", model_name.pluralize)
|
|
16
|
-
.gsub("%TABLE_NAME%", table_name || model_name.pluralize)
|
|
16
|
+
.gsub("%TABLE_NAME%", table_name&.to_s || model_name.pluralize)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -16,7 +16,9 @@ module AnnotateRb
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
model_path = file.gsub(/\.rb$/, "")
|
|
19
|
-
options[:model_dir].
|
|
19
|
+
model_dirs = options[:model_dir].flat_map { |dir| Dir[dir] }
|
|
20
|
+
model_dirs.each { |dir| model_path = model_path.delete_prefix(File.join(dir, "")) }
|
|
21
|
+
model_path = model_path.delete_prefix(File::SEPARATOR)
|
|
20
22
|
|
|
21
23
|
begin
|
|
22
24
|
get_loaded_model(model_path, file) || raise(BadModelFileError.new)
|
|
@@ -48,7 +48,11 @@ module AnnotateRb
|
|
|
48
48
|
|
|
49
49
|
# Returns the unmodified model columns
|
|
50
50
|
def raw_columns
|
|
51
|
-
@raw_columns ||= @
|
|
51
|
+
@raw_columns ||= if @options[:load_columns_from_schema]
|
|
52
|
+
connection.schema_cache.columns_hash(@klass.table_name).values.freeze
|
|
53
|
+
else
|
|
54
|
+
@klass.columns
|
|
55
|
+
end
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
def primary_key
|
|
@@ -80,7 +84,7 @@ module AnnotateRb
|
|
|
80
84
|
@column_defaults ||= @klass.column_defaults.each_with_object({}) do |(name, value), result|
|
|
81
85
|
column = @klass.columns_hash[name]
|
|
82
86
|
result[name] = if attribute_default_overridden?(name, column)
|
|
83
|
-
|
|
87
|
+
schema_default_with_enum_label(name, column)
|
|
84
88
|
else
|
|
85
89
|
enum_default(name, column, value)
|
|
86
90
|
end
|
|
@@ -296,9 +300,10 @@ module AnnotateRb
|
|
|
296
300
|
# shown. `enum_default_format` picks between that label, the raw value,
|
|
297
301
|
# and both.
|
|
298
302
|
def enum_default(name, column, label)
|
|
299
|
-
return label unless
|
|
303
|
+
return label unless enum_attribute?(name)
|
|
300
304
|
|
|
301
305
|
raw = schema_default_for(column)
|
|
306
|
+
return raw if label.nil?
|
|
302
307
|
return label if raw == label
|
|
303
308
|
|
|
304
309
|
case @options[:enum_default_format]
|
|
@@ -308,6 +313,27 @@ module AnnotateRb
|
|
|
308
313
|
end
|
|
309
314
|
end
|
|
310
315
|
|
|
316
|
+
# `enum :status, {...}, default: :shipped` sets a Ruby-side default without
|
|
317
|
+
# changing the schema default, so it lands in the override path. Map the
|
|
318
|
+
# schema value back to its label so the column annotates like any other
|
|
319
|
+
# enum column.
|
|
320
|
+
def schema_default_with_enum_label(name, column)
|
|
321
|
+
raw = schema_default_for(column)
|
|
322
|
+
label = enum_label_for(name, raw)
|
|
323
|
+
return raw if label.nil?
|
|
324
|
+
|
|
325
|
+
enum_default(name, column, label)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def enum_label_for(name, raw)
|
|
329
|
+
@klass.defined_enums[name]&.key(raw)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def enum_attribute?(name)
|
|
333
|
+
@klass.defined_enums.key?(name) ||
|
|
334
|
+
(@klass.respond_to?(:enumerized_attributes) && @klass.enumerized_attributes[name])
|
|
335
|
+
end
|
|
336
|
+
|
|
311
337
|
def schema_default_for(column)
|
|
312
338
|
return nil if column.nil? || column.default.nil? || column.default_function
|
|
313
339
|
cast_type_for(column).deserialize(column.default)
|
|
@@ -89,7 +89,17 @@ module AnnotateRb
|
|
|
89
89
|
patterns
|
|
90
90
|
.map { |f| FileNameResolver.call(f, @model_name, @table_name) }
|
|
91
91
|
.flat_map { |f| Dir.glob(f) }
|
|
92
|
-
.select { |f|
|
|
92
|
+
.select { |f| related_file_owned_by_model_root?(f, pattern_type) }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Additional file patterns are written by the user as explicit project paths, so a match outside
|
|
96
|
+
# every `root_dir` (e.g. `app/serializers/%MODEL_NAME%.rb` for a model living in a pack) belongs
|
|
97
|
+
# to the project and is still related. Matches inside another root directory remain excluded.
|
|
98
|
+
def related_file_owned_by_model_root?(file, pattern_type)
|
|
99
|
+
owner = owning_root_dir(file)
|
|
100
|
+
return true if owner == model_root_dir
|
|
101
|
+
|
|
102
|
+
owner.nil? && pattern_type.to_s == "additional_file_patterns"
|
|
93
103
|
end
|
|
94
104
|
|
|
95
105
|
def model_root_dir
|
|
@@ -23,6 +23,8 @@ module AnnotateRb
|
|
|
23
23
|
#
|
|
24
24
|
def call(file_name, annotation, annotation_position, options, model_class_name: nil)
|
|
25
25
|
return false unless File.exist?(file_name)
|
|
26
|
+
|
|
27
|
+
validate_annotation!(annotation)
|
|
26
28
|
old_content = File.read(file_name)
|
|
27
29
|
|
|
28
30
|
parser_klass = FileToParserMapper.map(file_name)
|
|
@@ -52,6 +54,16 @@ module AnnotateRb
|
|
|
52
54
|
|
|
53
55
|
true
|
|
54
56
|
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def validate_annotation!(annotation)
|
|
61
|
+
comment_only = annotation.to_s.split(/\r\n?|\n/, -1).all? do |line|
|
|
62
|
+
line.match?(/\A[ \t]*(?:#.*)?\z/)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
raise ArgumentError, "annotation contains non-comment content" unless comment_only
|
|
66
|
+
end
|
|
55
67
|
end
|
|
56
68
|
end
|
|
57
69
|
end
|
data/lib/annotate_rb/options.rb
CHANGED
|
@@ -56,6 +56,7 @@ module AnnotateRb
|
|
|
56
56
|
show_indexes_comments: false, # ModelAnnotator
|
|
57
57
|
show_indexes_include: false, # ModelAnnotator
|
|
58
58
|
show_virtual_columns: false, # ModelAnnotator
|
|
59
|
+
load_columns_from_schema: false, # ModelAnnotator
|
|
59
60
|
simple_indexes: false, # ModelAnnotator
|
|
60
61
|
sort: false, # ModelAnnotator
|
|
61
62
|
timestamp: false, # RouteAnnotator
|
|
@@ -125,6 +126,7 @@ module AnnotateRb
|
|
|
125
126
|
:ignore_model_sub_dir,
|
|
126
127
|
:ignore_unknown_models,
|
|
127
128
|
:include_version,
|
|
129
|
+
:load_columns_from_schema,
|
|
128
130
|
:show_check_constraints,
|
|
129
131
|
:show_unique_constraints,
|
|
130
132
|
:show_exclusion_constraints,
|
data/lib/annotate_rb/parser.rb
CHANGED
|
@@ -296,6 +296,11 @@ module AnnotateRb
|
|
|
296
296
|
"Place annotations directly above nested classes or modules instead of at the top of the file.") do
|
|
297
297
|
@options[:nested_position] = true
|
|
298
298
|
end
|
|
299
|
+
|
|
300
|
+
option_parser.on("--load-columns-from-schema",
|
|
301
|
+
"Load columns from schema to avoid ActiveRecord ignored/only column configuration") do
|
|
302
|
+
@options[:load_columns_from_schema] = true
|
|
303
|
+
end
|
|
299
304
|
end
|
|
300
305
|
|
|
301
306
|
def add_route_options_to_parser(option_parser)
|
|
@@ -13,6 +13,12 @@ module AnnotateRb
|
|
|
13
13
|
rescue
|
|
14
14
|
nil
|
|
15
15
|
end
|
|
16
|
+
|
|
17
|
+
# Tenanted models from activerecord-tenanted can't reach their database
|
|
18
|
+
# without a current tenant. The gem defines `db:tenant` to set its default
|
|
19
|
+
# tenant (ARTENANT, or the default tenant in local environments), the same
|
|
20
|
+
# way it does for the Rails console.
|
|
21
|
+
Rake::Task["db:tenant"].invoke if Rake::Task.task_defined?("db:tenant")
|
|
16
22
|
end
|
|
17
23
|
end
|
|
18
24
|
end
|