annotaterb 4.4.1 → 4.6.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 +43 -0
- data/README.md +29 -0
- data/VERSION +1 -1
- data/lib/annotate_rb/config_generator.rb +28 -0
- data/lib/annotate_rb/eager_loader.rb +6 -2
- data/lib/annotate_rb/model_annotator/annotated_file/generator.rb +92 -0
- data/lib/annotate_rb/model_annotator/annotated_file/updater.rb +46 -0
- data/lib/annotate_rb/model_annotator/annotated_file.rb +10 -0
- data/lib/annotate_rb/model_annotator/annotator.rb +2 -2
- data/lib/annotate_rb/model_annotator/file_name_resolver.rb +5 -0
- data/lib/annotate_rb/model_annotator/file_parser/annotation_finder.rb +103 -0
- data/lib/annotate_rb/model_annotator/file_parser/custom_parser.rb +217 -0
- data/lib/annotate_rb/model_annotator/file_parser/parsed_file.rb +94 -0
- data/lib/annotate_rb/model_annotator/file_parser/parsed_file_result.rb +54 -0
- data/lib/annotate_rb/model_annotator/file_parser.rb +12 -0
- data/lib/annotate_rb/model_annotator/model_class_getter.rb +7 -0
- data/lib/annotate_rb/model_annotator/model_files_getter.rb +4 -8
- data/lib/annotate_rb/model_annotator/model_wrapper.rb +11 -2
- data/lib/annotate_rb/model_annotator/pattern_getter.rb +2 -0
- data/lib/annotate_rb/model_annotator/related_files_list_builder.rb +3 -3
- data/lib/annotate_rb/model_annotator/single_file_annotation_remover.rb +10 -12
- data/lib/annotate_rb/model_annotator/single_file_annotator.rb +15 -8
- data/lib/annotate_rb/model_annotator/single_file_annotator_instruction.rb +1 -1
- data/lib/annotate_rb/model_annotator/single_file_remove_annotation_instruction.rb +1 -1
- data/lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb +113 -0
- data/lib/annotate_rb/model_annotator.rb +3 -4
- data/lib/annotate_rb/options.rb +4 -0
- data/lib/annotate_rb/parser.rb +9 -3
- data/lib/annotate_rb/runner.rb +5 -4
- data/lib/annotate_rb/tasks/annotate_models_migrate.rake +5 -0
- data/lib/annotate_rb.rb +1 -0
- data/lib/generators/annotate_rb/config/USAGE +6 -0
- data/lib/generators/annotate_rb/config/config_generator.rb +15 -0
- data/lib/generators/annotate_rb/hook/USAGE +7 -0
- data/lib/generators/annotate_rb/hook/hook_generator.rb +15 -0
- data/lib/generators/annotate_rb/install/install_generator.rb +3 -4
- data/lib/generators/annotate_rb/update_config/USAGE +6 -0
- data/lib/generators/annotate_rb/update_config/update_config_generator.rb +15 -0
- metadata +20 -8
- data/lib/annotate_rb/model_annotator/annotation_pattern_generator.rb +0 -19
- data/lib/annotate_rb/model_annotator/file_builder.rb +0 -57
- data/lib/annotate_rb/model_annotator/file_components.rb +0 -81
- data/lib/annotate_rb/model_annotator/magic_comment_parser.rb +0 -32
- /data/lib/generators/annotate_rb/{install → hook}/templates/annotate_rb.rake +0 -0
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.6.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:
|
11
|
+
date: 2024-02-27 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.
|
@@ -31,16 +31,19 @@ files:
|
|
31
31
|
- lib/annotate_rb/commands/print_help.rb
|
32
32
|
- lib/annotate_rb/commands/print_version.rb
|
33
33
|
- lib/annotate_rb/config_finder.rb
|
34
|
+
- lib/annotate_rb/config_generator.rb
|
34
35
|
- lib/annotate_rb/config_loader.rb
|
35
36
|
- lib/annotate_rb/core.rb
|
36
37
|
- lib/annotate_rb/eager_loader.rb
|
37
38
|
- lib/annotate_rb/helper.rb
|
38
39
|
- lib/annotate_rb/model_annotator.rb
|
40
|
+
- lib/annotate_rb/model_annotator/annotated_file.rb
|
41
|
+
- lib/annotate_rb/model_annotator/annotated_file/generator.rb
|
42
|
+
- lib/annotate_rb/model_annotator/annotated_file/updater.rb
|
39
43
|
- lib/annotate_rb/model_annotator/annotation_builder.rb
|
40
44
|
- lib/annotate_rb/model_annotator/annotation_decider.rb
|
41
45
|
- lib/annotate_rb/model_annotator/annotation_diff.rb
|
42
46
|
- lib/annotate_rb/model_annotator/annotation_diff_generator.rb
|
43
|
-
- lib/annotate_rb/model_annotator/annotation_pattern_generator.rb
|
44
47
|
- lib/annotate_rb/model_annotator/annotator.rb
|
45
48
|
- lib/annotate_rb/model_annotator/bad_model_file_error.rb
|
46
49
|
- lib/annotate_rb/model_annotator/column_annotation.rb
|
@@ -49,14 +52,16 @@ files:
|
|
49
52
|
- lib/annotate_rb/model_annotator/column_annotation/column_wrapper.rb
|
50
53
|
- lib/annotate_rb/model_annotator/column_annotation/default_value_builder.rb
|
51
54
|
- lib/annotate_rb/model_annotator/column_annotation/type_builder.rb
|
52
|
-
- lib/annotate_rb/model_annotator/file_builder.rb
|
53
|
-
- lib/annotate_rb/model_annotator/file_components.rb
|
54
55
|
- lib/annotate_rb/model_annotator/file_name_resolver.rb
|
56
|
+
- lib/annotate_rb/model_annotator/file_parser.rb
|
57
|
+
- lib/annotate_rb/model_annotator/file_parser/annotation_finder.rb
|
58
|
+
- lib/annotate_rb/model_annotator/file_parser/custom_parser.rb
|
59
|
+
- lib/annotate_rb/model_annotator/file_parser/parsed_file.rb
|
60
|
+
- lib/annotate_rb/model_annotator/file_parser/parsed_file_result.rb
|
55
61
|
- lib/annotate_rb/model_annotator/foreign_key_annotation.rb
|
56
62
|
- lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder.rb
|
57
63
|
- lib/annotate_rb/model_annotator/index_annotation.rb
|
58
64
|
- lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb
|
59
|
-
- lib/annotate_rb/model_annotator/magic_comment_parser.rb
|
60
65
|
- lib/annotate_rb/model_annotator/model_class_getter.rb
|
61
66
|
- lib/annotate_rb/model_annotator/model_files_getter.rb
|
62
67
|
- lib/annotate_rb/model_annotator/model_wrapper.rb
|
@@ -68,6 +73,7 @@ files:
|
|
68
73
|
- lib/annotate_rb/model_annotator/single_file_annotator.rb
|
69
74
|
- lib/annotate_rb/model_annotator/single_file_annotator_instruction.rb
|
70
75
|
- lib/annotate_rb/model_annotator/single_file_remove_annotation_instruction.rb
|
76
|
+
- lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb
|
71
77
|
- lib/annotate_rb/options.rb
|
72
78
|
- lib/annotate_rb/parser.rb
|
73
79
|
- lib/annotate_rb/rake_bootstrapper.rb
|
@@ -80,9 +86,15 @@ files:
|
|
80
86
|
- lib/annotate_rb/route_annotator/removal_processor.rb
|
81
87
|
- lib/annotate_rb/runner.rb
|
82
88
|
- lib/annotate_rb/tasks/annotate_models_migrate.rake
|
89
|
+
- lib/generators/annotate_rb/config/USAGE
|
90
|
+
- lib/generators/annotate_rb/config/config_generator.rb
|
91
|
+
- lib/generators/annotate_rb/hook/USAGE
|
92
|
+
- lib/generators/annotate_rb/hook/hook_generator.rb
|
93
|
+
- lib/generators/annotate_rb/hook/templates/annotate_rb.rake
|
83
94
|
- lib/generators/annotate_rb/install/USAGE
|
84
95
|
- lib/generators/annotate_rb/install/install_generator.rb
|
85
|
-
- lib/generators/annotate_rb/
|
96
|
+
- lib/generators/annotate_rb/update_config/USAGE
|
97
|
+
- lib/generators/annotate_rb/update_config/update_config_generator.rb
|
86
98
|
homepage: https://github.com/drwl/annotaterb
|
87
99
|
licenses:
|
88
100
|
- BSD-2-Clause
|
@@ -106,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
118
|
- !ruby/object:Gem::Version
|
107
119
|
version: '0'
|
108
120
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
121
|
+
rubygems_version: 3.5.6
|
110
122
|
signing_key:
|
111
123
|
specification_version: 4
|
112
124
|
summary: A gem for generating annotations for Rails projects.
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AnnotateRb
|
4
|
-
module ModelAnnotator
|
5
|
-
class AnnotationPatternGenerator
|
6
|
-
COMPAT_PREFIX = "== Schema Info"
|
7
|
-
COMPAT_PREFIX_MD = "## Schema Info"
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def call(options = Options.from({}))
|
11
|
-
if options[:wrapper_open]
|
12
|
-
return /(?:^(\n|\r\n)?# (?:#{options[:wrapper_open]}).*(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*)|^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/
|
13
|
-
end
|
14
|
-
/^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/o
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AnnotateRb
|
4
|
-
module ModelAnnotator
|
5
|
-
# Generates the text file content with annotations, these are then to be written to filesystem.
|
6
|
-
class FileBuilder
|
7
|
-
def initialize(file_components, annotation_position, options)
|
8
|
-
@file_components = file_components
|
9
|
-
@annotation_position = annotation_position
|
10
|
-
@options = options
|
11
|
-
|
12
|
-
@new_wrapped_annotations = wrapped_content(@file_components.new_annotations)
|
13
|
-
end
|
14
|
-
|
15
|
-
def generate_content_with_new_annotations
|
16
|
-
# Need to keep `.to_s` for now since the it can be either a String or Symbol
|
17
|
-
annotation_write_position = @options[@annotation_position].to_s
|
18
|
-
|
19
|
-
_content = if %w[after bottom].include?(annotation_write_position)
|
20
|
-
@file_components.magic_comments + (@file_components.pure_file_content.rstrip + "\n\n" + @new_wrapped_annotations)
|
21
|
-
elsif @file_components.magic_comments.empty?
|
22
|
-
@file_components.magic_comments + @new_wrapped_annotations + @file_components.pure_file_content.lstrip
|
23
|
-
else
|
24
|
-
@file_components.magic_comments + "\n" + @new_wrapped_annotations + @file_components.pure_file_content.lstrip
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_existing_annotations
|
29
|
-
return "" if !@file_components.has_annotations?
|
30
|
-
|
31
|
-
annotation_pattern = AnnotationPatternGenerator.call(@options)
|
32
|
-
|
33
|
-
new_annotation = @file_components.space_before_annotation + @new_wrapped_annotations + @file_components.space_after_annotation
|
34
|
-
|
35
|
-
_content = @file_components.current_file_content.sub(annotation_pattern, new_annotation)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def wrapped_content(content)
|
41
|
-
wrapper_open = if @options[:wrapper_open]
|
42
|
-
"# #{@options[:wrapper_open]}\n"
|
43
|
-
else
|
44
|
-
""
|
45
|
-
end
|
46
|
-
|
47
|
-
wrapper_close = if @options[:wrapper_close]
|
48
|
-
"# #{@options[:wrapper_close]}\n"
|
49
|
-
else
|
50
|
-
""
|
51
|
-
end
|
52
|
-
|
53
|
-
_wrapped_info_block = "#{wrapper_open}#{content}#{wrapper_close}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AnnotateRb
|
4
|
-
module ModelAnnotator
|
5
|
-
class FileComponents
|
6
|
-
SKIP_ANNOTATION_STRING = "# -*- SkipSchemaAnnotations"
|
7
|
-
SOME_PATTERN = /\A(?<start>\s*).*?\n(?<end>\s*)\z/m # Unsure what this pattern is
|
8
|
-
|
9
|
-
attr_reader :new_annotations
|
10
|
-
|
11
|
-
def initialize(file_content, new_annotations, options)
|
12
|
-
@file_content = file_content
|
13
|
-
@diff = AnnotationDiffGenerator.new(file_content, new_annotations).generate
|
14
|
-
@options = options
|
15
|
-
@annotation_pattern = AnnotationPatternGenerator.call(options)
|
16
|
-
@new_annotations = new_annotations
|
17
|
-
end
|
18
|
-
|
19
|
-
def current_file_content
|
20
|
-
@file_content
|
21
|
-
end
|
22
|
-
|
23
|
-
# TODO: Rename method once it's clear what this actually does
|
24
|
-
def space_before_annotation
|
25
|
-
return @space_before_annotation if defined?(@space_before_annotation)
|
26
|
-
|
27
|
-
match = current_annotations.match(SOME_PATTERN)
|
28
|
-
@space_before_annotation = if match
|
29
|
-
match[:start]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# TODO: Rename method once it's clear what this actually does
|
34
|
-
def space_after_annotation
|
35
|
-
return @space_after_annotation if defined?(@space_after_annotation)
|
36
|
-
|
37
|
-
match = current_annotations.match(SOME_PATTERN)
|
38
|
-
@space_after_annotation = if match
|
39
|
-
match[:end]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def pure_file_content
|
44
|
-
@pure_file_content ||=
|
45
|
-
begin
|
46
|
-
content_without_magic_comments = @file_content.gsub(MagicCommentParser::MAGIC_COMMENTS_REGEX, "")
|
47
|
-
content_without_annotations = content_without_magic_comments.sub(@annotation_pattern, "")
|
48
|
-
|
49
|
-
content_without_annotations
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def magic_comments
|
54
|
-
@magic_comments ||= MagicCommentParser.call(@file_content)
|
55
|
-
end
|
56
|
-
|
57
|
-
def has_skip_string?
|
58
|
-
@has_skip_string ||= @file_content.include?(SKIP_ANNOTATION_STRING)
|
59
|
-
end
|
60
|
-
|
61
|
-
def has_annotations?
|
62
|
-
@has_annotations ||= @diff.current_columns.present?
|
63
|
-
end
|
64
|
-
|
65
|
-
def annotations_changed?
|
66
|
-
@has_annotations_changed ||= @diff.changed?
|
67
|
-
end
|
68
|
-
|
69
|
-
def current_annotations
|
70
|
-
@current_annotations ||=
|
71
|
-
if has_annotations?
|
72
|
-
# `#has_annotations?` uses a different regex pattern than the one in `@annotation_pattern`,
|
73
|
-
# this could lead to unexpected behavior
|
74
|
-
@file_content.match(@annotation_pattern).to_s
|
75
|
-
else
|
76
|
-
""
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AnnotateRb
|
4
|
-
module ModelAnnotator
|
5
|
-
# Extracts magic comments strings and returns them
|
6
|
-
class MagicCommentParser
|
7
|
-
MAGIC_COMMENTS = [
|
8
|
-
HASH_ENCODING = /(^#\s*encoding:.*(?:\n|r\n))/,
|
9
|
-
HASH_CODING = /(^# coding:.*(?:\n|\r\n))/,
|
10
|
-
HASH_FROZEN_STRING = /(^#\s*frozen_string_literal:.+(?:\n|\r\n))/,
|
11
|
-
STAR_ENCODING = /(^# -\*- encoding\s?:.*(?:\n|\r\n))/,
|
12
|
-
STAR_CODING = /(^# -\*- coding:.*(?:\n|\r\n))/,
|
13
|
-
STAR_FROZEN_STRING = /(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/,
|
14
|
-
SORBET_TYPED_STRING = /(^#\s*typed:.*(?:\n|r\n))/.freeze
|
15
|
-
].freeze
|
16
|
-
|
17
|
-
MAGIC_COMMENTS_REGEX = Regexp.union(*MAGIC_COMMENTS).freeze
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def call(content)
|
21
|
-
magic_comments = content.scan(MAGIC_COMMENTS_REGEX).flatten.compact
|
22
|
-
|
23
|
-
if magic_comments.any?
|
24
|
-
magic_comments.join
|
25
|
-
else
|
26
|
-
""
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
File without changes
|