annotaterb 4.3.0 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -2
- data/VERSION +1 -1
- data/lib/annotate_rb/model_annotator/annotation_builder.rb +19 -4
- data/lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb +5 -3
- data/lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb +3 -3
- data/lib/annotate_rb/model_annotator/column_annotation/column_wrapper.rb +9 -6
- data/lib/annotate_rb/model_annotator/column_annotation/type_builder.rb +3 -2
- data/lib/annotate_rb/model_annotator/file_builder.rb +2 -3
- data/lib/annotate_rb/model_annotator/file_components.rb +3 -0
- data/lib/annotate_rb/model_annotator/model_wrapper.rb +10 -2
- data/lib/annotate_rb/model_annotator/single_file_annotator.rb +1 -1
- data/lib/annotate_rb/options.rb +10 -2
- data/lib/annotate_rb/parser.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349c4c734ded99ebac4d6ec075372fe814dff54e7edd7834a4b7c254aa046571
|
4
|
+
data.tar.gz: 715b408a71123bc45986f4aca53c1c34b0debb92b01dc770085a7ba5aac6ae45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d843a40644a70550177193b9f1e559c541852384bf4e26f489a45d6ad486d8ddf6157d94abc9c98072acfad802e3144db40fe9ba1e6a3b00018d7865c92dc78a
|
7
|
+
data.tar.gz: e3706615de5bca13aa90353aec34bcc9a728400c139321d051edac045d4c2f24edc032129f666eb012da7b88587bd90bab979e40f77fb25c0568b39559a8302a
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,36 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v4.3.1](https://github.com/drwl/annotaterb/tree/v4.3.1) (2023-06-15)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.
|
5
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.3.0...v4.3.1)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Column defaults change in migration [\#45](https://github.com/drwl/annotaterb/issues/45)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Bump version to v4.3.1 [\#46](https://github.com/drwl/annotaterb/pull/46) ([drwl](https://github.com/drwl))
|
14
|
+
- Prettify column defaults [\#44](https://github.com/drwl/annotaterb/pull/44) ([drwl](https://github.com/drwl))
|
15
|
+
- Generate changelog for v4.3.0 [\#42](https://github.com/drwl/annotaterb/pull/42) ([drwl](https://github.com/drwl))
|
16
|
+
|
17
|
+
## [v4.3.0](https://github.com/drwl/annotaterb/tree/v4.3.0) (2023-06-10)
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.2.0...v4.3.0)
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- Bump version to v4.3.0 [\#41](https://github.com/drwl/annotaterb/pull/41) ([drwl](https://github.com/drwl))
|
24
|
+
- Add `ANNOTATERB_SKIP_ON_DB_TASKS` ENV var to skip auto annotations [\#40](https://github.com/drwl/annotaterb/pull/40) ([drwl](https://github.com/drwl))
|
25
|
+
|
26
|
+
## [v4.2.0](https://github.com/drwl/annotaterb/tree/v4.2.0) (2023-06-02)
|
27
|
+
|
28
|
+
[Full Changelog](https://github.com/drwl/annotaterb/compare/v4.1.1...v4.2.0)
|
6
29
|
|
7
30
|
**Merged pull requests:**
|
8
31
|
|
9
32
|
- Specify `standard` gem version [\#39](https://github.com/drwl/annotaterb/pull/39) ([drwl](https://github.com/drwl))
|
33
|
+
- Generate changelog for 4.2 again [\#38](https://github.com/drwl/annotaterb/pull/38) ([drwl](https://github.com/drwl))
|
10
34
|
- Bump version to v4.2.0 [\#37](https://github.com/drwl/annotaterb/pull/37) ([drwl](https://github.com/drwl))
|
11
35
|
- Generate changelog for 4.2 [\#36](https://github.com/drwl/annotaterb/pull/36) ([drwl](https://github.com/drwl))
|
12
36
|
- Improve tests for `ColumnAnnotation::*` [\#35](https://github.com/drwl/annotaterb/pull/35) ([drwl](https://github.com/drwl))
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.4.0
|
@@ -12,14 +12,14 @@ module AnnotateRb
|
|
12
12
|
MD_NAMES_OVERHEAD = 6
|
13
13
|
MD_TYPE_ALLOWANCE = 18
|
14
14
|
|
15
|
-
def initialize(klass, options
|
15
|
+
def initialize(klass, options)
|
16
16
|
@model = ModelWrapper.new(klass, options)
|
17
17
|
@options = options
|
18
18
|
@info = "" # TODO: Make array and build string that way
|
19
19
|
end
|
20
20
|
|
21
21
|
def build
|
22
|
-
@info = "#
|
22
|
+
@info = "#{header}\n"
|
23
23
|
@info += schema_header_text
|
24
24
|
|
25
25
|
max_size = @model.max_schema_info_width
|
@@ -51,6 +51,7 @@ module AnnotateRb
|
|
51
51
|
|
52
52
|
def header
|
53
53
|
header = @options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
|
54
|
+
header = "# #{header}"
|
54
55
|
version = begin
|
55
56
|
ActiveRecord::Migrator.current_version
|
56
57
|
rescue
|
@@ -69,11 +70,11 @@ module AnnotateRb
|
|
69
70
|
info << "#"
|
70
71
|
|
71
72
|
if @options[:format_markdown]
|
72
|
-
info << "# Table name: `#{
|
73
|
+
info << "# Table name: `#{table_name}`"
|
73
74
|
info << "#"
|
74
75
|
info << "# ### Columns"
|
75
76
|
else
|
76
|
-
info << "# Table name: #{
|
77
|
+
info << "# Table name: #{table_name}"
|
77
78
|
end
|
78
79
|
info << "#\n" # We want the last line break
|
79
80
|
|
@@ -93,6 +94,20 @@ module AnnotateRb
|
|
93
94
|
|
94
95
|
info.join("\n")
|
95
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def table_name
|
101
|
+
table_name = @model.table_name
|
102
|
+
display_table_comments = @options[:with_comment] && @options[:with_table_comments]
|
103
|
+
|
104
|
+
if display_table_comments && @model.has_table_comments?
|
105
|
+
table_comment = "(#{@model.table_comments.gsub(/\n/, "\\n")})"
|
106
|
+
table_name = "#{table_name}#{table_comment}"
|
107
|
+
end
|
108
|
+
|
109
|
+
table_name
|
110
|
+
end
|
96
111
|
end
|
97
112
|
end
|
98
113
|
end
|
@@ -21,11 +21,13 @@ module AnnotateRb
|
|
21
21
|
|
22
22
|
table_indices = @model.retrieve_indexes_from_table
|
23
23
|
column_indices = table_indices.select { |ind| ind.columns.include?(@column.name) }
|
24
|
+
column_defaults = @model.column_defaults
|
24
25
|
|
25
|
-
column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices).build
|
26
|
-
formatted_column_type = TypeBuilder.new(@column, @options).build
|
26
|
+
column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices, column_defaults).build
|
27
|
+
formatted_column_type = TypeBuilder.new(@column, @options, column_defaults).build
|
27
28
|
|
28
|
-
|
29
|
+
display_column_comments = @options[:with_comment] && @options[:with_column_comments]
|
30
|
+
col_name = if display_column_comments && @model.with_comments? && @column.comment
|
29
31
|
"#{@column.name}(#{@column.comment.gsub(/\n/, '\\n')})"
|
30
32
|
else
|
31
33
|
@column.name
|
@@ -7,8 +7,8 @@ module AnnotateRb
|
|
7
7
|
# Don't show default value for these column types
|
8
8
|
NO_DEFAULT_COL_TYPES = %w[json jsonb hstore].freeze
|
9
9
|
|
10
|
-
def initialize(column, options, is_primary_key, column_indices)
|
11
|
-
@column = ColumnWrapper.new(column)
|
10
|
+
def initialize(column, options, is_primary_key, column_indices, column_defaults)
|
11
|
+
@column = ColumnWrapper.new(column, column_defaults)
|
12
12
|
@options = options
|
13
13
|
@is_primary_key = is_primary_key
|
14
14
|
@column_indices = column_indices
|
@@ -20,7 +20,7 @@ module AnnotateRb
|
|
20
20
|
column_type = @column.column_type_string
|
21
21
|
attrs = []
|
22
22
|
|
23
|
-
|
23
|
+
if !@column.raw_default.nil? && !hide_default?
|
24
24
|
schema_default = "default(#{@column.default_string})"
|
25
25
|
|
26
26
|
attrs << schema_default
|
@@ -4,18 +4,21 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module ColumnAnnotation
|
6
6
|
class ColumnWrapper
|
7
|
-
def initialize(column)
|
7
|
+
def initialize(column, column_defaults)
|
8
8
|
@column = column
|
9
|
+
@column_defaults = column_defaults
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def raw_default
|
13
|
+
@column.default
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_value
|
17
|
+
@column_defaults[@column.name]
|
15
18
|
end
|
16
19
|
|
17
20
|
def default_string
|
18
|
-
quote(
|
21
|
+
quote(default_value)
|
19
22
|
end
|
20
23
|
|
21
24
|
def type
|
@@ -8,8 +8,9 @@ module AnnotateRb
|
|
8
8
|
# Example: show "integer" instead of "integer(4)"
|
9
9
|
NO_LIMIT_COL_TYPES = %w[integer bigint boolean].freeze
|
10
10
|
|
11
|
-
def initialize(column, options)
|
12
|
-
|
11
|
+
def initialize(column, options, column_defaults)
|
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
14
|
@options = options
|
14
15
|
end
|
15
16
|
|
@@ -4,13 +4,12 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
# Generates the text file content with annotations, these are then to be written to filesystem.
|
6
6
|
class FileBuilder
|
7
|
-
def initialize(file_components,
|
7
|
+
def initialize(file_components, annotation_position, options)
|
8
8
|
@file_components = file_components
|
9
|
-
@new_annotations = new_annotations
|
10
9
|
@annotation_position = annotation_position
|
11
10
|
@options = options
|
12
11
|
|
13
|
-
@new_wrapped_annotations = wrapped_content(new_annotations)
|
12
|
+
@new_wrapped_annotations = wrapped_content(@file_components.new_annotations)
|
14
13
|
end
|
15
14
|
|
16
15
|
def generate_content_with_new_annotations
|
@@ -6,11 +6,14 @@ module AnnotateRb
|
|
6
6
|
SKIP_ANNOTATION_STRING = "# -*- SkipSchemaAnnotations"
|
7
7
|
SOME_PATTERN = /\A(?<start>\s*).*?\n(?<end>\s*)\z/m # Unsure what this pattern is
|
8
8
|
|
9
|
+
attr_reader :new_annotations
|
10
|
+
|
9
11
|
def initialize(file_content, new_annotations, options)
|
10
12
|
@file_content = file_content
|
11
13
|
@diff = AnnotationDiffGenerator.new(file_content, new_annotations).generate
|
12
14
|
@options = options
|
13
15
|
@annotation_pattern = AnnotationPatternGenerator.call(options)
|
16
|
+
@new_annotations = new_annotations
|
14
17
|
end
|
15
18
|
|
16
19
|
def current_file_content
|
@@ -49,6 +49,15 @@ module AnnotateRb
|
|
49
49
|
@klass.table_exists?
|
50
50
|
end
|
51
51
|
|
52
|
+
def table_comments
|
53
|
+
@klass.connection.table_comment(@klass.table_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_table_comments?
|
57
|
+
@klass.connection.respond_to?(:table_comment) &&
|
58
|
+
@klass.connection.table_comment(@klass.table_name).present?
|
59
|
+
end
|
60
|
+
|
52
61
|
def column_defaults
|
53
62
|
@klass.column_defaults
|
54
63
|
end
|
@@ -110,8 +119,7 @@ module AnnotateRb
|
|
110
119
|
end
|
111
120
|
|
112
121
|
def with_comments?
|
113
|
-
@with_comments ||=
|
114
|
-
raw_columns.first.respond_to?(:comment) &&
|
122
|
+
@with_comments ||= raw_columns.first.respond_to?(:comment) &&
|
115
123
|
raw_columns.map(&:comment).any? { |comment| !comment.nil? }
|
116
124
|
end
|
117
125
|
|
@@ -26,7 +26,7 @@ module AnnotateRb
|
|
26
26
|
old_content = File.read(file_name)
|
27
27
|
|
28
28
|
file_components = FileComponents.new(old_content, annotation, options)
|
29
|
-
builder = FileBuilder.new(file_components,
|
29
|
+
builder = FileBuilder.new(file_components, annotation_position, options)
|
30
30
|
|
31
31
|
return false if file_components.has_skip_string?
|
32
32
|
return false if !file_components.annotations_changed? && !options[:force]
|
data/lib/annotate_rb/options.rb
CHANGED
@@ -51,7 +51,9 @@ module AnnotateRb
|
|
51
51
|
sort: false, # ModelAnnotator
|
52
52
|
timestamp: false, # RouteAnnotator
|
53
53
|
trace: false, # ModelAnnotator, but is part of Core
|
54
|
-
with_comment: true # ModelAnnotator
|
54
|
+
with_comment: true, # ModelAnnotator
|
55
|
+
with_column_comments: nil, # ModelAnnotator
|
56
|
+
with_table_comments: nil # ModelAnnotator
|
55
57
|
}.freeze
|
56
58
|
|
57
59
|
OTHER_OPTIONS = {
|
@@ -113,7 +115,9 @@ module AnnotateRb
|
|
113
115
|
:sort,
|
114
116
|
:timestamp,
|
115
117
|
:trace,
|
116
|
-
:with_comment
|
118
|
+
:with_comment,
|
119
|
+
:with_column_comments,
|
120
|
+
:with_table_comments
|
117
121
|
].freeze
|
118
122
|
|
119
123
|
OTHER_OPTION_KEYS = [
|
@@ -187,6 +191,10 @@ module AnnotateRb
|
|
187
191
|
@options[:wrapper_open] ||= @options[:wrapper]
|
188
192
|
@options[:wrapper_close] ||= @options[:wrapper]
|
189
193
|
|
194
|
+
# Set column and table comments to default to :with_comment, if not set
|
195
|
+
@options[:with_column_comments] = @options[:with_comment] if @options[:with_column_comments].nil?
|
196
|
+
@options[:with_table_comments] = @options[:with_comment] if @options[:with_table_comments].nil?
|
197
|
+
|
190
198
|
self
|
191
199
|
end
|
192
200
|
|
data/lib/annotate_rb/parser.rb
CHANGED
@@ -217,6 +217,31 @@ module AnnotateRb
|
|
217
217
|
"include database comments in model annotations") do
|
218
218
|
@options[:with_comment] = true
|
219
219
|
end
|
220
|
+
|
221
|
+
option_parser.on("--without-comment",
|
222
|
+
"include database comments in model annotations") do
|
223
|
+
@options[:with_comment] = false
|
224
|
+
end
|
225
|
+
|
226
|
+
option_parser.on("--with-column-comments",
|
227
|
+
"include column comments in model annotations") do
|
228
|
+
@options[:with_column_comments] = true
|
229
|
+
end
|
230
|
+
|
231
|
+
option_parser.on("--without-column-comments",
|
232
|
+
"exclude column comments in model annotations") do
|
233
|
+
@options[:with_column_comments] = false
|
234
|
+
end
|
235
|
+
|
236
|
+
option_parser.on("--with-table-comments",
|
237
|
+
"include table comments in model annotations") do
|
238
|
+
@options[:with_table_comments] = true
|
239
|
+
end
|
240
|
+
|
241
|
+
option_parser.on("--without-table-comments",
|
242
|
+
"exclude table comments in model annotations") do
|
243
|
+
@options[:with_table_comments] = false
|
244
|
+
end
|
220
245
|
end
|
221
246
|
|
222
247
|
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.4.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: 2023-06-
|
11
|
+
date: 2023-06-24 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.
|