annotaterb 4.6.0 → 4.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/VERSION +1 -1
- data/lib/annotate_rb/model_annotator/annotation_builder.rb +15 -4
- data/lib/annotate_rb/model_annotator/annotation_decider.rb +4 -0
- data/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb +57 -0
- data/lib/annotate_rb/model_annotator/check_constraint_annotation.rb +9 -0
- data/lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb +1 -1
- data/lib/annotate_rb/model_annotator/column_annotation/column_wrapper.rb +3 -2
- data/lib/annotate_rb/model_annotator/column_annotation/default_value_builder.rb +4 -1
- data/lib/annotate_rb/model_annotator/column_annotation/type_builder.rb +1 -1
- data/lib/annotate_rb/model_annotator.rb +1 -0
- data/lib/annotate_rb/options.rb +6 -2
- data/lib/annotate_rb/parser.rb +16 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7b61329d5886c3d24def7469ff273e6692c08a5f8f2340a7f6471f993190e17
|
4
|
+
data.tar.gz: 8fcb5a79d2be122867131b8a3779318958326564f6c3c36e4c53e4e0ee7b4250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c9fe857ae8f3627ff4fe42a419c6123cf9697419d766798abc81b3cf40c6cfb23ad6978d9daab4db7e6888fdfbf9574f4562a9949ab5344b7d3f6df168aff80
|
7
|
+
data.tar.gz: 3cf70f50b4c9ef6f97b08ab91dc7b538806dce0be9a1b4b45be68d132afa74828b306e63544f1be18739a7a85149f4af19f033feeb5899ae575ef61726be27d5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v4.7.0](https://github.com/drwl/annotaterb/tree/v4.7.0) (2024-03-27)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.6.0...v4.7.0)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Feature request: better custom type representation [\#97](https://github.com/drwl/annotaterb/issues/97)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Bump version to v4.7.0 [\#100](https://github.com/drwl/annotaterb/pull/100) ([drwl](https://github.com/drwl))
|
14
|
+
- Add configurable classes list with `to_s` representation [\#98](https://github.com/drwl/annotaterb/pull/98) ([viralpraxis](https://github.com/viralpraxis))
|
15
|
+
- Generate changelog for v4.6.0 [\#96](https://github.com/drwl/annotaterb/pull/96) ([drwl](https://github.com/drwl))
|
16
|
+
|
17
|
+
## [v4.6.0](https://github.com/drwl/annotaterb/tree/v4.6.0) (2024-02-27)
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.5.0...v4.6.0)
|
20
|
+
|
21
|
+
**Closed issues:**
|
22
|
+
|
23
|
+
- Add support for `data_migrate` gem [\#89](https://github.com/drwl/annotaterb/issues/89)
|
24
|
+
|
25
|
+
**Merged pull requests:**
|
26
|
+
|
27
|
+
- Bump version to v4.6.0 [\#95](https://github.com/drwl/annotaterb/pull/95) ([drwl](https://github.com/drwl))
|
28
|
+
- Add support for parsing RSpec files [\#94](https://github.com/drwl/annotaterb/pull/94) ([drwl](https://github.com/drwl))
|
29
|
+
- Add support for model name without namespace in resolver [\#93](https://github.com/drwl/annotaterb/pull/93) ([drwl](https://github.com/drwl))
|
30
|
+
- Fixes for `RelatedFilesListBuilder` [\#92](https://github.com/drwl/annotaterb/pull/92) ([drwl](https://github.com/drwl))
|
31
|
+
- Refactor `AnnotatedFile` classes [\#91](https://github.com/drwl/annotaterb/pull/91) ([drwl](https://github.com/drwl))
|
32
|
+
- Add support for data\_migrate gem [\#90](https://github.com/drwl/annotaterb/pull/90) ([cmer](https://github.com/cmer))
|
33
|
+
- Support non-model files in `CustomParser` [\#88](https://github.com/drwl/annotaterb/pull/88) ([drwl](https://github.com/drwl))
|
34
|
+
- Fix flakey integration test [\#87](https://github.com/drwl/annotaterb/pull/87) ([drwl](https://github.com/drwl))
|
35
|
+
- Improve integration tests [\#86](https://github.com/drwl/annotaterb/pull/86) ([drwl](https://github.com/drwl))
|
36
|
+
- Add Zeitwerk support [\#85](https://github.com/drwl/annotaterb/pull/85) ([drwl](https://github.com/drwl))
|
37
|
+
- Improve annotate after adding new migration integration test [\#84](https://github.com/drwl/annotaterb/pull/84) ([drwl](https://github.com/drwl))
|
38
|
+
- Add integration test using force [\#81](https://github.com/drwl/annotaterb/pull/81) ([drwl](https://github.com/drwl))
|
39
|
+
- Generate changelog for v4.5.0 [\#80](https://github.com/drwl/annotaterb/pull/80) ([drwl](https://github.com/drwl))
|
40
|
+
- Fix annotations swallowing comments [\#72](https://github.com/drwl/annotaterb/pull/72) ([drwl](https://github.com/drwl))
|
41
|
+
|
3
42
|
## [v4.5.0](https://github.com/drwl/annotaterb/tree/v4.5.0) (2024-02-08)
|
4
43
|
|
5
44
|
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.4.1...v4.5.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.7.1
|
@@ -44,6 +44,10 @@ module AnnotateRb
|
|
44
44
|
@info += ForeignKeyAnnotation::AnnotationBuilder.new(@model, @options).build
|
45
45
|
end
|
46
46
|
|
47
|
+
if @options[:show_check_constraints] && @model.table_exists?
|
48
|
+
@info += CheckConstraintAnnotation::AnnotationBuilder.new(@model, @options).build
|
49
|
+
end
|
50
|
+
|
47
51
|
@info += schema_footer_text
|
48
52
|
|
49
53
|
@info
|
@@ -52,12 +56,19 @@ module AnnotateRb
|
|
52
56
|
def header
|
53
57
|
header = @options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
|
54
58
|
header = "# #{header}"
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
|
60
|
+
if @options.get_state(:current_version).nil?
|
61
|
+
migration_version = begin
|
62
|
+
ActiveRecord::Migrator.current_version
|
63
|
+
rescue
|
64
|
+
0
|
65
|
+
end
|
66
|
+
|
67
|
+
@options.set_state(:current_version, migration_version)
|
59
68
|
end
|
60
69
|
|
70
|
+
version = @options.get_state(:current_version)
|
71
|
+
|
61
72
|
if @options[:include_version] && version > 0
|
62
73
|
header += "\n# Schema version: #{version}"
|
63
74
|
end
|
@@ -18,6 +18,10 @@ module AnnotateRb
|
|
18
18
|
klass = ModelClassGetter.call(@file, @options)
|
19
19
|
|
20
20
|
klass_is_a_class = klass.is_a?(Class)
|
21
|
+
# Methods such as #superclass only exist on a class. Because of how the code is structured, `klass` could be a
|
22
|
+
# module that does not support the #superclass method, so we want to return early.
|
23
|
+
return false if !klass_is_a_class
|
24
|
+
|
21
25
|
klass_inherits_active_record_base = klass < ActiveRecord::Base
|
22
26
|
klass_is_not_abstract = klass.respond_to?(:abstract_class) && !klass.abstract_class?
|
23
27
|
klass_table_exists = klass.respond_to?(:abstract_class) && klass.table_exists?
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module CheckConstraintAnnotation
|
6
|
+
class AnnotationBuilder
|
7
|
+
def initialize(model, options)
|
8
|
+
@model = model
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
constraint_info = if @options[:format_markdown]
|
14
|
+
"#\n# ### Check Constraints\n#\n"
|
15
|
+
else
|
16
|
+
"#\n# Check Constraints\n#\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
return "" unless @model.connection.respond_to?(:supports_check_constraints?) &&
|
20
|
+
@model.connection.supports_check_constraints? && @model.connection.respond_to?(:check_constraints)
|
21
|
+
|
22
|
+
check_constraints = @model.connection.check_constraints(@model.table_name)
|
23
|
+
return "" if check_constraints.empty?
|
24
|
+
|
25
|
+
max_size = check_constraints.map { |check_constraint| check_constraint.name.size }.max + 1
|
26
|
+
check_constraints.sort_by(&:name).each do |check_constraint|
|
27
|
+
expression = check_constraint.expression ? "(#{check_constraint.expression.squish})" : nil
|
28
|
+
|
29
|
+
constraint_info += if @options[:format_markdown]
|
30
|
+
cc_info_in_markdown(check_constraint.name, expression)
|
31
|
+
else
|
32
|
+
cc_info_string(check_constraint.name, expression, max_size)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
constraint_info
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def cc_info_in_markdown(name, expression)
|
42
|
+
cc_info_markdown = sprintf("# * `%s`", name)
|
43
|
+
cc_info_markdown += sprintf(": `%s`", expression) if expression
|
44
|
+
cc_info_markdown += "\n"
|
45
|
+
|
46
|
+
cc_info_markdown
|
47
|
+
end
|
48
|
+
|
49
|
+
def cc_info_string(name, expression, max_size)
|
50
|
+
# standard:disable Lint/FormatParameterMismatch
|
51
|
+
sprintf("# %-#{max_size}.#{max_size}s %s", name, expression).rstrip + "\n"
|
52
|
+
# standard:enable Lint/FormatParameterMismatch
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -8,7 +8,7 @@ module AnnotateRb
|
|
8
8
|
NO_DEFAULT_COL_TYPES = %w[json jsonb hstore].freeze
|
9
9
|
|
10
10
|
def initialize(column, options, is_primary_key, column_indices, column_defaults)
|
11
|
-
@column = ColumnWrapper.new(column, column_defaults)
|
11
|
+
@column = ColumnWrapper.new(column, column_defaults, options)
|
12
12
|
@options = options
|
13
13
|
@is_primary_key = is_primary_key
|
14
14
|
@column_indices = column_indices
|
@@ -4,9 +4,10 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module ColumnAnnotation
|
6
6
|
class ColumnWrapper
|
7
|
-
def initialize(column, column_defaults)
|
7
|
+
def initialize(column, column_defaults, options)
|
8
8
|
@column = column
|
9
9
|
@column_defaults = column_defaults
|
10
|
+
@options = options
|
10
11
|
end
|
11
12
|
|
12
13
|
def raw_default
|
@@ -88,7 +89,7 @@ module AnnotateRb
|
|
88
89
|
|
89
90
|
# Simple quoting for the default column value
|
90
91
|
def quote(value)
|
91
|
-
DefaultValueBuilder.new(value).build
|
92
|
+
DefaultValueBuilder.new(value, @options).build
|
92
93
|
end
|
93
94
|
end
|
94
95
|
end
|
@@ -4,8 +4,9 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module ColumnAnnotation
|
6
6
|
class DefaultValueBuilder
|
7
|
-
def initialize(value)
|
7
|
+
def initialize(value, options)
|
8
8
|
@value = value
|
9
|
+
@options = options
|
9
10
|
end
|
10
11
|
|
11
12
|
# @return [String]
|
@@ -27,6 +28,8 @@ module AnnotateRb
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def quote(value)
|
31
|
+
return value.to_s.inspect if @options[:classes_default_to_s]&.include?(value.class.name)
|
32
|
+
|
30
33
|
case value
|
31
34
|
when NilClass then "NULL"
|
32
35
|
when TrueClass then "TRUE"
|
@@ -10,7 +10,7 @@ module AnnotateRb
|
|
10
10
|
|
11
11
|
def initialize(column, options, column_defaults)
|
12
12
|
# Passing `column_defaults` for posterity, don't actually need it here since it's not used
|
13
|
-
@column = ColumnWrapper.new(column, column_defaults)
|
13
|
+
@column = ColumnWrapper.new(column, column_defaults, options)
|
14
14
|
@options = options
|
15
15
|
end
|
16
16
|
|
@@ -26,5 +26,6 @@ module AnnotateRb
|
|
26
26
|
autoload :AnnotatedFile, "annotate_rb/model_annotator/annotated_file"
|
27
27
|
autoload :FileParser, "annotate_rb/model_annotator/file_parser"
|
28
28
|
autoload :ZeitwerkClassGetter, "annotate_rb/model_annotator/zeitwerk_class_getter"
|
29
|
+
autoload :CheckConstraintAnnotation, "annotate_rb/model_annotator/check_constraint_annotation"
|
29
30
|
end
|
30
31
|
end
|
data/lib/annotate_rb/options.rb
CHANGED
@@ -45,6 +45,7 @@ module AnnotateRb
|
|
45
45
|
ignore_unknown_models: false, # ModelAnnotator
|
46
46
|
include_version: false, # ModelAnnotator
|
47
47
|
show_complete_foreign_keys: false, # ModelAnnotator
|
48
|
+
show_check_constraints: false, # ModelAnnotator
|
48
49
|
show_foreign_keys: true, # ModelAnnotator
|
49
50
|
show_indexes: true, # ModelAnnotator
|
50
51
|
simple_indexes: false, # ModelAnnotator
|
@@ -76,7 +77,8 @@ module AnnotateRb
|
|
76
77
|
target_action: :do_annotations, # Core; Possible values: :do_annotations, :remove_annotations
|
77
78
|
wrapper: nil, # ModelAnnotator, RouteAnnotator
|
78
79
|
wrapper_close: nil, # ModelAnnotator, RouteAnnotator
|
79
|
-
wrapper_open: nil # ModelAnnotator, RouteAnnotator
|
80
|
+
wrapper_open: nil, # ModelAnnotator, RouteAnnotator,
|
81
|
+
classes_default_to_s: [] # ModelAnnotator
|
80
82
|
}.freeze
|
81
83
|
|
82
84
|
PATH_OPTIONS = {
|
@@ -108,6 +110,7 @@ module AnnotateRb
|
|
108
110
|
:ignore_model_sub_dir,
|
109
111
|
:ignore_unknown_models,
|
110
112
|
:include_version,
|
113
|
+
:show_check_constraints,
|
111
114
|
:show_complete_foreign_keys,
|
112
115
|
:show_foreign_keys,
|
113
116
|
:show_indexes,
|
@@ -135,7 +138,8 @@ module AnnotateRb
|
|
135
138
|
:target_action,
|
136
139
|
:wrapper,
|
137
140
|
:wrapper_close,
|
138
|
-
:wrapper_open
|
141
|
+
:wrapper_open,
|
142
|
+
:classes_default_to_s
|
139
143
|
].freeze
|
140
144
|
|
141
145
|
PATH_OPTION_KEYS = [
|
data/lib/annotate_rb/parser.rb
CHANGED
@@ -9,7 +9,7 @@ module AnnotateRb
|
|
9
9
|
|
10
10
|
BANNER_STRING = <<~BANNER.freeze
|
11
11
|
Usage: annotaterb [command] [options]
|
12
|
-
|
12
|
+
|
13
13
|
Commands:
|
14
14
|
models [options]
|
15
15
|
routes [options]
|
@@ -198,6 +198,12 @@ module AnnotateRb
|
|
198
198
|
@options[:simple_indexes] = true
|
199
199
|
end
|
200
200
|
|
201
|
+
option_parser.on("-c",
|
202
|
+
"--show-check-constraints",
|
203
|
+
"List the table's check constraints in the annotation") do
|
204
|
+
@options[:show_check_constraints] = true
|
205
|
+
end
|
206
|
+
|
201
207
|
option_parser.on("--hide-limit-column-types VALUES",
|
202
208
|
"don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
|
203
209
|
@options[:hide_limit_column_types] = values.to_s
|
@@ -248,6 +254,15 @@ module AnnotateRb
|
|
248
254
|
"exclude table comments in model annotations") do
|
249
255
|
@options[:with_table_comments] = false
|
250
256
|
end
|
257
|
+
|
258
|
+
option_parser.on("--classes-default-to-s class",
|
259
|
+
"Custom classes to be represented with `to_s`, may be used multiple times") do |klass|
|
260
|
+
@options[:classes_default_to_s] = if @options[:classes_default_to_s].present?
|
261
|
+
[*@options[:classes_default_to_s], klass]
|
262
|
+
else
|
263
|
+
[klass]
|
264
|
+
end
|
265
|
+
end
|
251
266
|
end
|
252
267
|
|
253
268
|
def add_route_options_to_parser(option_parser)
|
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.
|
4
|
+
version: 4.7.1
|
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: 2024-
|
11
|
+
date: 2024-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
|
14
14
|
on the database schema.
|
@@ -46,6 +46,8 @@ files:
|
|
46
46
|
- lib/annotate_rb/model_annotator/annotation_diff_generator.rb
|
47
47
|
- lib/annotate_rb/model_annotator/annotator.rb
|
48
48
|
- lib/annotate_rb/model_annotator/bad_model_file_error.rb
|
49
|
+
- lib/annotate_rb/model_annotator/check_constraint_annotation.rb
|
50
|
+
- lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb
|
49
51
|
- lib/annotate_rb/model_annotator/column_annotation.rb
|
50
52
|
- lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb
|
51
53
|
- lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb
|