annotaterb 4.1.0 → 4.2.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 +68 -0
- data/README.md +4 -5
- data/VERSION +1 -1
- data/exe/annotaterb +7 -7
- data/lib/annotate_rb/active_record_patch.rb +2 -0
- data/lib/annotate_rb/commands/annotate_models.rb +0 -1
- data/lib/annotate_rb/commands/annotate_routes.rb +0 -1
- data/lib/annotate_rb/commands/print_help.rb +0 -1
- data/lib/annotate_rb/commands/print_version.rb +0 -1
- data/lib/annotate_rb/commands.rb +4 -4
- data/lib/annotate_rb/config_finder.rb +1 -1
- data/lib/annotate_rb/config_loader.rb +2 -2
- data/lib/annotate_rb/core.rb +3 -3
- data/lib/annotate_rb/helper.rb +16 -0
- data/lib/annotate_rb/model_annotator/{annotation_generator.rb → annotation_builder.rb} +18 -14
- data/lib/annotate_rb/model_annotator/annotation_decider.rb +10 -12
- data/lib/annotate_rb/model_annotator/annotation_diff.rb +19 -0
- data/lib/annotate_rb/model_annotator/annotation_diff_generator.rb +44 -0
- data/lib/annotate_rb/model_annotator/annotation_pattern_generator.rb +3 -3
- data/lib/annotate_rb/model_annotator/annotator.rb +12 -53
- data/lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb +135 -0
- data/lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb +104 -0
- data/lib/annotate_rb/model_annotator/column_annotation/column_wrapper.rb +103 -0
- data/lib/annotate_rb/model_annotator/column_annotation/type_builder.rb +54 -0
- data/lib/annotate_rb/model_annotator/column_annotation.rb +12 -0
- data/lib/annotate_rb/model_annotator/file_builder.rb +58 -0
- data/lib/annotate_rb/model_annotator/file_components.rb +78 -0
- data/lib/annotate_rb/model_annotator/file_name_resolver.rb +3 -3
- data/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder.rb +57 -0
- data/lib/annotate_rb/model_annotator/foreign_key_annotation.rb +9 -0
- data/lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb +113 -0
- data/lib/annotate_rb/model_annotator/index_annotation.rb +9 -0
- data/lib/annotate_rb/model_annotator/magic_comment_parser.rb +32 -0
- data/lib/annotate_rb/model_annotator/model_class_getter.rb +6 -6
- data/lib/annotate_rb/model_annotator/model_files_getter.rb +12 -10
- data/lib/annotate_rb/model_annotator/model_wrapper.rb +44 -37
- data/lib/annotate_rb/model_annotator/pattern_getter.rb +142 -10
- data/lib/annotate_rb/model_annotator/project_annotation_remover.rb +65 -0
- data/lib/annotate_rb/model_annotator/project_annotator.rb +63 -0
- data/lib/annotate_rb/model_annotator/related_files_list_builder.rb +16 -18
- data/lib/annotate_rb/model_annotator/single_file_annotation_remover.rb +37 -0
- data/lib/annotate_rb/model_annotator/single_file_annotator.rb +49 -0
- data/lib/annotate_rb/model_annotator/{file_annotator_instruction.rb → single_file_annotator_instruction.rb} +2 -2
- data/lib/annotate_rb/model_annotator/single_file_remove_annotation_instruction.rb +15 -0
- data/lib/annotate_rb/model_annotator.rb +25 -24
- data/lib/annotate_rb/options.rb +20 -25
- data/lib/annotate_rb/parser.rb +150 -142
- data/lib/annotate_rb/rake_bootstrapper.rb +8 -8
- data/lib/annotate_rb/route_annotator/annotation_processor.rb +7 -8
- data/lib/annotate_rb/route_annotator/annotator.rb +2 -2
- data/lib/annotate_rb/route_annotator/base_processor.rb +3 -3
- data/lib/annotate_rb/route_annotator/header_generator.rb +15 -15
- data/lib/annotate_rb/route_annotator/helper.rb +9 -9
- data/lib/annotate_rb/route_annotator/removal_processor.rb +4 -4
- data/lib/annotate_rb/route_annotator.rb +6 -6
- data/lib/annotate_rb/runner.rb +0 -4
- data/lib/annotate_rb/tasks/annotate_models_migrate.rake +5 -5
- data/lib/annotate_rb.rb +19 -19
- data/lib/generators/annotate_rb/install/install_generator.rb +3 -2
- data/lib/generators/annotate_rb/install/templates/annotate_rb.rake +1 -1
- metadata +24 -16
- data/lib/annotate_rb/model_annotator/column_annotation_builder.rb +0 -92
- data/lib/annotate_rb/model_annotator/column_attributes_builder.rb +0 -102
- data/lib/annotate_rb/model_annotator/column_type_builder.rb +0 -51
- data/lib/annotate_rb/model_annotator/column_wrapper.rb +0 -84
- data/lib/annotate_rb/model_annotator/constants.rb +0 -22
- data/lib/annotate_rb/model_annotator/file_annotation_remover.rb +0 -25
- data/lib/annotate_rb/model_annotator/file_annotator.rb +0 -83
- data/lib/annotate_rb/model_annotator/file_patterns.rb +0 -129
- data/lib/annotate_rb/model_annotator/foreign_key_annotation_builder.rb +0 -55
- data/lib/annotate_rb/model_annotator/helper.rb +0 -107
- data/lib/annotate_rb/model_annotator/index_annotation_builder.rb +0 -74
- data/lib/annotate_rb/model_annotator/model_file_annotator.rb +0 -55
|
@@ -5,7 +5,7 @@ module AnnotateRb
|
|
|
5
5
|
# Given a model file and options, this class will return a list of related files (e.g. fixture, controllers, etc)
|
|
6
6
|
# to also annotate
|
|
7
7
|
class RelatedFilesListBuilder
|
|
8
|
-
RELATED_TYPES = %w
|
|
8
|
+
RELATED_TYPES = %w[test fixture factory serializer scaffold controller helper].freeze
|
|
9
9
|
|
|
10
10
|
def initialize(file, model_name, table_name, options)
|
|
11
11
|
@file = file
|
|
@@ -35,17 +35,15 @@ module AnnotateRb
|
|
|
35
35
|
def related_files_for_pattern(pattern_type)
|
|
36
36
|
patterns = PatternGetter.call(@options, pattern_type)
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_related_files
|
|
38
|
+
patterns
|
|
39
|
+
.map { |f| FileNameResolver.call(f, @model_name, @table_name) }
|
|
40
|
+
.map { |f| Dir.glob(f) }
|
|
41
|
+
.flatten
|
|
44
42
|
end
|
|
45
43
|
|
|
46
44
|
def add_related_test_files
|
|
47
45
|
position_key = :position_in_test
|
|
48
|
-
pattern_type =
|
|
46
|
+
pattern_type = "test"
|
|
49
47
|
|
|
50
48
|
related_files = related_files_for_pattern(pattern_type)
|
|
51
49
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -55,7 +53,7 @@ module AnnotateRb
|
|
|
55
53
|
|
|
56
54
|
def add_related_fixture_files
|
|
57
55
|
position_key = :position_in_fixture
|
|
58
|
-
pattern_type =
|
|
56
|
+
pattern_type = "fixture"
|
|
59
57
|
|
|
60
58
|
related_files = related_files_for_pattern(pattern_type)
|
|
61
59
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -65,7 +63,7 @@ module AnnotateRb
|
|
|
65
63
|
|
|
66
64
|
def add_related_factory_files
|
|
67
65
|
position_key = :position_in_factory
|
|
68
|
-
pattern_type =
|
|
66
|
+
pattern_type = "factory"
|
|
69
67
|
|
|
70
68
|
related_files = related_files_for_pattern(pattern_type)
|
|
71
69
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -75,7 +73,7 @@ module AnnotateRb
|
|
|
75
73
|
|
|
76
74
|
def add_related_serializer_files
|
|
77
75
|
position_key = :position_in_serializer
|
|
78
|
-
pattern_type =
|
|
76
|
+
pattern_type = "serializer"
|
|
79
77
|
|
|
80
78
|
related_files = related_files_for_pattern(pattern_type)
|
|
81
79
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -85,7 +83,7 @@ module AnnotateRb
|
|
|
85
83
|
|
|
86
84
|
def add_related_scaffold_files
|
|
87
85
|
position_key = :position_in_scaffold # Key does not exist
|
|
88
|
-
pattern_type =
|
|
86
|
+
pattern_type = "scaffold"
|
|
89
87
|
|
|
90
88
|
related_files = related_files_for_pattern(pattern_type)
|
|
91
89
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -95,7 +93,7 @@ module AnnotateRb
|
|
|
95
93
|
|
|
96
94
|
def add_related_controller_files
|
|
97
95
|
position_key = :position_in_controller # Key does not exist
|
|
98
|
-
pattern_type =
|
|
96
|
+
pattern_type = "controller"
|
|
99
97
|
|
|
100
98
|
related_files = related_files_for_pattern(pattern_type)
|
|
101
99
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -105,7 +103,7 @@ module AnnotateRb
|
|
|
105
103
|
|
|
106
104
|
def add_related_helper_files
|
|
107
105
|
position_key = :position_in_helper # Key does not exist
|
|
108
|
-
pattern_type =
|
|
106
|
+
pattern_type = "helper"
|
|
109
107
|
|
|
110
108
|
related_files = related_files_for_pattern(pattern_type)
|
|
111
109
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -115,7 +113,7 @@ module AnnotateRb
|
|
|
115
113
|
|
|
116
114
|
def add_related_admin_files
|
|
117
115
|
position_key = :position_in_admin # Key does not exist
|
|
118
|
-
pattern_type =
|
|
116
|
+
pattern_type = "admin"
|
|
119
117
|
|
|
120
118
|
related_files = related_files_for_pattern(pattern_type)
|
|
121
119
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -124,8 +122,8 @@ module AnnotateRb
|
|
|
124
122
|
end
|
|
125
123
|
|
|
126
124
|
def add_additional_file_patterns
|
|
127
|
-
position_key = :position_in_additional_file_patterns
|
|
128
|
-
pattern_type =
|
|
125
|
+
position_key = :position_in_additional_file_patterns
|
|
126
|
+
pattern_type = "additional_file_patterns"
|
|
129
127
|
|
|
130
128
|
related_files = related_files_for_pattern(pattern_type)
|
|
131
129
|
files_with_position_key = related_files.map { |f| [f, position_key] }
|
|
@@ -134,4 +132,4 @@ module AnnotateRb
|
|
|
134
132
|
end
|
|
135
133
|
end
|
|
136
134
|
end
|
|
137
|
-
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AnnotateRb
|
|
4
|
+
module ModelAnnotator
|
|
5
|
+
class SingleFileAnnotationRemover
|
|
6
|
+
class << self
|
|
7
|
+
def call_with_instructions(instruction)
|
|
8
|
+
call(instruction.file, instruction.options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(file_name, options = Options.from({}))
|
|
12
|
+
return false unless File.exist?(file_name)
|
|
13
|
+
old_content = File.read(file_name)
|
|
14
|
+
|
|
15
|
+
file_components = FileComponents.new(old_content, "", options)
|
|
16
|
+
|
|
17
|
+
return false if file_components.has_skip_string?
|
|
18
|
+
# TODO: Uncomment below after tests are fixed
|
|
19
|
+
# return false if !file_components.has_annotations?
|
|
20
|
+
|
|
21
|
+
wrapper_open = if options[:wrapper_open]
|
|
22
|
+
"# #{options[:wrapper_open]}\n"
|
|
23
|
+
else
|
|
24
|
+
""
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
generated_pattern = AnnotationPatternGenerator.call(options)
|
|
28
|
+
updated_file_content = old_content.sub!(/(#{wrapper_open})?#{generated_pattern}/, "")
|
|
29
|
+
|
|
30
|
+
File.open(file_name, "wb") { |f| f.puts updated_file_content }
|
|
31
|
+
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AnnotateRb
|
|
4
|
+
module ModelAnnotator
|
|
5
|
+
class SingleFileAnnotator
|
|
6
|
+
class << self
|
|
7
|
+
def call_with_instructions(instruction)
|
|
8
|
+
call(instruction.file, instruction.annotation, instruction.position, instruction.options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Add a schema block to a file. If the file already contains
|
|
12
|
+
# a schema info block (a comment starting with "== Schema Information"),
|
|
13
|
+
# check if it matches the block that is already there. If so, leave it be.
|
|
14
|
+
# If not, remove the old info block and write a new one.
|
|
15
|
+
#
|
|
16
|
+
# == Returns:
|
|
17
|
+
# true or false depending on whether the file was modified.
|
|
18
|
+
#
|
|
19
|
+
# === Options (opts)
|
|
20
|
+
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
|
|
21
|
+
# :position_in_*<Symbol>:: where to place the annotated section in fixture or model file,
|
|
22
|
+
# :before, :top, :after or :bottom. Default is :before.
|
|
23
|
+
#
|
|
24
|
+
def call(file_name, annotation, annotation_position, options = {})
|
|
25
|
+
return false unless File.exist?(file_name)
|
|
26
|
+
old_content = File.read(file_name)
|
|
27
|
+
|
|
28
|
+
file_components = FileComponents.new(old_content, annotation, options)
|
|
29
|
+
builder = FileBuilder.new(file_components, annotation, annotation_position, options)
|
|
30
|
+
|
|
31
|
+
return false if file_components.has_skip_string?
|
|
32
|
+
return false if !file_components.annotations_changed? && !options[:force]
|
|
33
|
+
|
|
34
|
+
abort "AnnotateRb error. #{file_name} needs to be updated, but annotaterb was run with `--frozen`." if options[:frozen]
|
|
35
|
+
|
|
36
|
+
updated_file_content = if !file_components.has_annotations? || options[:force]
|
|
37
|
+
builder.generate_content_with_new_annotations
|
|
38
|
+
else
|
|
39
|
+
builder.update_existing_annotations
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
File.open(file_name, "wb") { |f| f.puts updated_file_content }
|
|
43
|
+
|
|
44
|
+
true
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
|
5
|
-
# A plain old Ruby object (PORO) that contains all necessary information for
|
|
6
|
-
class
|
|
5
|
+
# A plain old Ruby object (PORO) that contains all necessary information for SingleFileAnnotator
|
|
6
|
+
class SingleFileAnnotatorInstruction
|
|
7
7
|
def initialize(file, annotation, position, options = {})
|
|
8
8
|
@file = file # Path to file
|
|
9
9
|
@annotation = annotation # Annotation string
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AnnotateRb
|
|
4
|
+
module ModelAnnotator
|
|
5
|
+
# A plain old Ruby object (PORO) that contains all necessary information for SingleFileAnnotationRemover
|
|
6
|
+
class SingleFileRemoveAnnotationInstruction
|
|
7
|
+
def initialize(file, options = {})
|
|
8
|
+
@file = file # Path to file
|
|
9
|
+
@options = options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
attr_reader :file, :options
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -2,29 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
|
5
|
-
autoload :Annotator,
|
|
6
|
-
autoload :
|
|
7
|
-
autoload :
|
|
8
|
-
autoload :
|
|
9
|
-
autoload :
|
|
10
|
-
autoload :
|
|
11
|
-
autoload :
|
|
12
|
-
autoload :
|
|
13
|
-
autoload :
|
|
14
|
-
autoload :
|
|
15
|
-
autoload :
|
|
16
|
-
autoload :
|
|
17
|
-
autoload :
|
|
18
|
-
autoload :
|
|
19
|
-
autoload :
|
|
20
|
-
autoload :
|
|
21
|
-
autoload :
|
|
22
|
-
autoload :
|
|
23
|
-
autoload :
|
|
24
|
-
autoload :
|
|
25
|
-
autoload :
|
|
26
|
-
autoload :
|
|
27
|
-
autoload :
|
|
28
|
-
autoload :
|
|
5
|
+
autoload :Annotator, "annotate_rb/model_annotator/annotator"
|
|
6
|
+
autoload :PatternGetter, "annotate_rb/model_annotator/pattern_getter"
|
|
7
|
+
autoload :BadModelFileError, "annotate_rb/model_annotator/bad_model_file_error"
|
|
8
|
+
autoload :FileNameResolver, "annotate_rb/model_annotator/file_name_resolver"
|
|
9
|
+
autoload :SingleFileAnnotationRemover, "annotate_rb/model_annotator/single_file_annotation_remover"
|
|
10
|
+
autoload :AnnotationPatternGenerator, "annotate_rb/model_annotator/annotation_pattern_generator"
|
|
11
|
+
autoload :ModelClassGetter, "annotate_rb/model_annotator/model_class_getter"
|
|
12
|
+
autoload :ModelFilesGetter, "annotate_rb/model_annotator/model_files_getter"
|
|
13
|
+
autoload :SingleFileAnnotator, "annotate_rb/model_annotator/single_file_annotator"
|
|
14
|
+
autoload :ModelWrapper, "annotate_rb/model_annotator/model_wrapper"
|
|
15
|
+
autoload :AnnotationBuilder, "annotate_rb/model_annotator/annotation_builder"
|
|
16
|
+
autoload :ColumnAnnotation, "annotate_rb/model_annotator/column_annotation"
|
|
17
|
+
autoload :IndexAnnotation, "annotate_rb/model_annotator/index_annotation"
|
|
18
|
+
autoload :ForeignKeyAnnotation, "annotate_rb/model_annotator/foreign_key_annotation"
|
|
19
|
+
autoload :RelatedFilesListBuilder, "annotate_rb/model_annotator/related_files_list_builder"
|
|
20
|
+
autoload :AnnotationDecider, "annotate_rb/model_annotator/annotation_decider"
|
|
21
|
+
autoload :SingleFileAnnotatorInstruction, "annotate_rb/model_annotator/single_file_annotator_instruction"
|
|
22
|
+
autoload :SingleFileRemoveAnnotationInstruction, "annotate_rb/model_annotator/single_file_remove_annotation_instruction"
|
|
23
|
+
autoload :AnnotationDiffGenerator, "annotate_rb/model_annotator/annotation_diff_generator"
|
|
24
|
+
autoload :AnnotationDiff, "annotate_rb/model_annotator/annotation_diff"
|
|
25
|
+
autoload :FileBuilder, "annotate_rb/model_annotator/file_builder"
|
|
26
|
+
autoload :MagicCommentParser, "annotate_rb/model_annotator/magic_comment_parser"
|
|
27
|
+
autoload :FileComponents, "annotate_rb/model_annotator/file_components"
|
|
28
|
+
autoload :ProjectAnnotator, "annotate_rb/model_annotator/project_annotator"
|
|
29
|
+
autoload :ProjectAnnotationRemover, "annotate_rb/model_annotator/project_annotation_remover"
|
|
29
30
|
end
|
|
30
31
|
end
|
data/lib/annotate_rb/options.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "forwardable"
|
|
4
4
|
|
|
5
5
|
module AnnotateRb
|
|
6
6
|
# Used to hold all of the options when annotating models and routes.
|
|
@@ -16,12 +16,13 @@ module AnnotateRb
|
|
|
16
16
|
|
|
17
17
|
POSITION_OPTIONS = {
|
|
18
18
|
position: nil, # ModelAnnotator, RouteAnnotator
|
|
19
|
+
position_in_additional_file_patterns: nil, # ModelAnnotator
|
|
19
20
|
position_in_class: nil, # ModelAnnotator
|
|
20
|
-
position_in_factory: nil, #
|
|
21
|
-
position_in_fixture: nil, #
|
|
21
|
+
position_in_factory: nil, # ModelAnnotator
|
|
22
|
+
position_in_fixture: nil, # ModelAnnotator
|
|
22
23
|
position_in_routes: nil, # RouteAnnotator
|
|
23
|
-
position_in_serializer: nil, #
|
|
24
|
-
position_in_test: nil
|
|
24
|
+
position_in_serializer: nil, # ModelAnnotator
|
|
25
|
+
position_in_test: nil # ModelAnnotator
|
|
25
26
|
}.freeze
|
|
26
27
|
|
|
27
28
|
FLAG_OPTIONS = {
|
|
@@ -50,7 +51,7 @@ module AnnotateRb
|
|
|
50
51
|
sort: false, # ModelAnnotator
|
|
51
52
|
timestamp: false, # RouteAnnotator
|
|
52
53
|
trace: false, # ModelAnnotator, but is part of Core
|
|
53
|
-
with_comment: true
|
|
54
|
+
with_comment: true # ModelAnnotator
|
|
54
55
|
}.freeze
|
|
55
56
|
|
|
56
57
|
OTHER_OPTIONS = {
|
|
@@ -59,10 +60,10 @@ module AnnotateRb
|
|
|
59
60
|
debug: false, # Core
|
|
60
61
|
|
|
61
62
|
# ModelAnnotator
|
|
62
|
-
hide_default_column_types:
|
|
63
|
+
hide_default_column_types: "",
|
|
63
64
|
|
|
64
65
|
# ModelAnnotator
|
|
65
|
-
hide_limit_column_types:
|
|
66
|
+
hide_limit_column_types: "",
|
|
66
67
|
|
|
67
68
|
ignore_columns: nil, # ModelAnnotator
|
|
68
69
|
ignore_routes: nil, # RouteAnnotator
|
|
@@ -73,26 +74,20 @@ module AnnotateRb
|
|
|
73
74
|
target_action: :do_annotations, # Core; Possible values: :do_annotations, :remove_annotations
|
|
74
75
|
wrapper: nil, # ModelAnnotator, RouteAnnotator
|
|
75
76
|
wrapper_close: nil, # ModelAnnotator, RouteAnnotator
|
|
76
|
-
wrapper_open: nil
|
|
77
|
+
wrapper_open: nil # ModelAnnotator, RouteAnnotator
|
|
77
78
|
}.freeze
|
|
78
79
|
|
|
79
80
|
PATH_OPTIONS = {
|
|
80
81
|
additional_file_patterns: [], # ModelAnnotator
|
|
81
|
-
model_dir: [
|
|
82
|
+
model_dir: ["app/models"], # ModelAnnotator
|
|
82
83
|
require: [], # Core
|
|
83
|
-
root_dir: [
|
|
84
|
+
root_dir: [""] # Core; Old model Annotate code depends on it being empty when not provided another value
|
|
84
85
|
# `root_dir` can also be a string but should get converted into an array with that string as the sole element when
|
|
85
86
|
# that happens.
|
|
86
87
|
}.freeze
|
|
87
88
|
|
|
88
89
|
DEFAULT_OPTIONS = {}.merge(POSITION_OPTIONS, FLAG_OPTIONS, OTHER_OPTIONS, PATH_OPTIONS).freeze
|
|
89
90
|
|
|
90
|
-
POSITION_OPTION_KEYS = [
|
|
91
|
-
:position,
|
|
92
|
-
:position_in_class,
|
|
93
|
-
:position_in_routes,
|
|
94
|
-
].freeze
|
|
95
|
-
|
|
96
91
|
FLAG_OPTION_KEYS = [
|
|
97
92
|
:classified_sort,
|
|
98
93
|
:exclude_controllers,
|
|
@@ -118,7 +113,7 @@ module AnnotateRb
|
|
|
118
113
|
:sort,
|
|
119
114
|
:timestamp,
|
|
120
115
|
:trace,
|
|
121
|
-
:with_comment
|
|
116
|
+
:with_comment
|
|
122
117
|
].freeze
|
|
123
118
|
|
|
124
119
|
OTHER_OPTION_KEYS = [
|
|
@@ -136,21 +131,21 @@ module AnnotateRb
|
|
|
136
131
|
:target_action,
|
|
137
132
|
:wrapper,
|
|
138
133
|
:wrapper_close,
|
|
139
|
-
:wrapper_open
|
|
134
|
+
:wrapper_open
|
|
140
135
|
].freeze
|
|
141
136
|
|
|
142
137
|
PATH_OPTION_KEYS = [
|
|
143
138
|
:additional_file_patterns,
|
|
144
139
|
:model_dir,
|
|
145
140
|
:require,
|
|
146
|
-
:root_dir
|
|
141
|
+
:root_dir
|
|
147
142
|
].freeze
|
|
148
143
|
|
|
149
144
|
ALL_OPTION_KEYS = [
|
|
150
|
-
|
|
145
|
+
POSITION_OPTIONS.keys, FLAG_OPTION_KEYS, OTHER_OPTION_KEYS, PATH_OPTION_KEYS
|
|
151
146
|
].flatten.freeze
|
|
152
147
|
|
|
153
|
-
POSITION_DEFAULT =
|
|
148
|
+
POSITION_DEFAULT = "before"
|
|
154
149
|
|
|
155
150
|
# Want this to be read only after initializing
|
|
156
151
|
def_delegator :@options, :[]
|
|
@@ -175,8 +170,8 @@ module AnnotateRb
|
|
|
175
170
|
# 1) Use the value if it's defined
|
|
176
171
|
# 2) Use value from :position if it's defined
|
|
177
172
|
# 3) Use default
|
|
178
|
-
|
|
179
|
-
@options[key] =
|
|
173
|
+
POSITION_OPTIONS.keys.each do |key|
|
|
174
|
+
@options[key] = Helper.fallback(
|
|
180
175
|
@options[key], @options[:position], POSITION_DEFAULT
|
|
181
176
|
)
|
|
182
177
|
end
|
|
@@ -184,7 +179,7 @@ module AnnotateRb
|
|
|
184
179
|
# Unpack path options if we're passed in a String
|
|
185
180
|
PATH_OPTION_KEYS.each do |key|
|
|
186
181
|
if @options[key].is_a?(String)
|
|
187
|
-
@options[key] = @options[key].split(
|
|
182
|
+
@options[key] = @options[key].split(",").map(&:strip).reject(&:empty?)
|
|
188
183
|
end
|
|
189
184
|
end
|
|
190
185
|
|