annotaterb 4.1.1 → 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/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 +1 -1
- data/lib/annotate_rb/model_annotator/annotation_diff_generator.rb +9 -9
- 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 -26
- 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 +22 -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 -77
- 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
data/lib/annotate_rb/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "optparse"
|
2
2
|
|
3
3
|
module AnnotateRb
|
4
4
|
# Class for handling command line arguments
|
@@ -28,10 +28,10 @@ module AnnotateRb
|
|
28
28
|
FORMAT_TYPES = %w[bare rdoc yard markdown].freeze
|
29
29
|
|
30
30
|
COMMAND_MAP = {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
"models" => :models,
|
32
|
+
"routes" => :routes,
|
33
|
+
"version" => :version,
|
34
|
+
"help" => :help
|
35
35
|
}.freeze
|
36
36
|
|
37
37
|
def initialize(args, existing_options)
|
@@ -72,13 +72,13 @@ module AnnotateRb
|
|
72
72
|
version: Commands::PrintVersion.new
|
73
73
|
}
|
74
74
|
|
75
|
-
if @commands.any?
|
76
|
-
|
75
|
+
@options[:command] = if @commands.any?
|
76
|
+
map[@commands.first]
|
77
77
|
elsif @commands.size > 1
|
78
78
|
# TODO: Should raise or alert user that multiple commands were selected but only 1 command will be ran
|
79
|
-
|
79
|
+
map[@commands.first]
|
80
80
|
else # None
|
81
|
-
|
81
|
+
map[:help]
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -87,14 +87,14 @@ module AnnotateRb
|
|
87
87
|
option_parser.banner = BANNER_STRING
|
88
88
|
|
89
89
|
# ------------------------------------------------------------------------------------------------------------=
|
90
|
-
option_parser.separator(
|
91
|
-
option_parser.separator(
|
90
|
+
option_parser.separator("")
|
91
|
+
option_parser.separator("Options:")
|
92
92
|
|
93
|
-
option_parser.on(
|
93
|
+
option_parser.on("-v", "--version", "Display the version..") do
|
94
94
|
@commands << :version
|
95
95
|
end
|
96
96
|
|
97
|
-
option_parser.on(
|
97
|
+
option_parser.on("-h", "--help", "You're looking at it.") do
|
98
98
|
@commands << :help
|
99
99
|
end
|
100
100
|
|
@@ -108,130 +108,130 @@ module AnnotateRb
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def add_wrapper_options_to_parser(option_parser)
|
111
|
-
option_parser.on(
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
option_parser.on("--w",
|
112
|
+
"--wrapper STR",
|
113
|
+
"Wrap annotation with the text passed as parameter.",
|
114
|
+
"If --w option is used, the same text will be used as opening and closing") do |wrapper|
|
115
115
|
@options[:wrapper] = wrapper
|
116
116
|
end
|
117
117
|
|
118
|
-
option_parser.on(
|
119
|
-
|
120
|
-
|
118
|
+
option_parser.on("--wo",
|
119
|
+
"--wrapper-open STR",
|
120
|
+
"Annotation wrapper opening.") do |wrapper_open|
|
121
121
|
@options[:wrapper_open] = wrapper_open
|
122
122
|
end
|
123
123
|
|
124
|
-
option_parser.on(
|
125
|
-
|
126
|
-
|
124
|
+
option_parser.on("--wc",
|
125
|
+
"--wrapper-close STR",
|
126
|
+
"Annotation wrapper closing") do |wrapper_close|
|
127
127
|
@options[:wrapper_close] = wrapper_close
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
def add_utils_to_parser(option_parser)
|
132
|
-
option_parser.on(
|
133
|
-
|
132
|
+
option_parser.on("--force",
|
133
|
+
"Force new annotations even if there are no changes.") do
|
134
134
|
@options[:force] = true
|
135
135
|
end
|
136
136
|
|
137
|
-
option_parser.on(
|
138
|
-
|
137
|
+
option_parser.on("--debug",
|
138
|
+
"Prints the options and outputs messages to make it easier to debug.") do
|
139
139
|
@options[:debug] = true
|
140
140
|
end
|
141
141
|
|
142
|
-
option_parser.on(
|
143
|
-
|
142
|
+
option_parser.on("--frozen",
|
143
|
+
"Do not allow to change annotations. Exits non-zero if there are going to be changes to files.") do
|
144
144
|
@options[:frozen] = true
|
145
145
|
end
|
146
146
|
|
147
|
-
option_parser.on(
|
148
|
-
|
147
|
+
option_parser.on("--trace",
|
148
|
+
"If unable to annotate a file, print the full stack trace, not just the exception message.") do
|
149
149
|
@options[:trace] = true
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
def add_model_options_to_parser(option_parser)
|
154
|
-
option_parser.separator(
|
155
|
-
option_parser.separator(
|
156
|
-
option_parser.separator(
|
157
|
-
option_parser.separator(
|
158
|
-
|
159
|
-
option_parser.on(
|
160
|
-
|
161
|
-
|
154
|
+
option_parser.separator("")
|
155
|
+
option_parser.separator("Annotate model options:")
|
156
|
+
option_parser.separator(" " * 4 + "Usage: annotaterb models [options]")
|
157
|
+
option_parser.separator("")
|
158
|
+
|
159
|
+
option_parser.on("-a",
|
160
|
+
"--active-admin",
|
161
|
+
"Annotate active_admin models") do
|
162
162
|
@options[:active_admin] = true
|
163
163
|
end
|
164
164
|
|
165
|
-
option_parser.on(
|
166
|
-
|
165
|
+
option_parser.on("--show-migration",
|
166
|
+
"Include the migration version number in the annotation") do
|
167
167
|
@options[:include_version] = true
|
168
168
|
end
|
169
169
|
|
170
|
-
option_parser.on(
|
171
|
-
|
172
|
-
|
170
|
+
option_parser.on("-k",
|
171
|
+
"--show-foreign-keys",
|
172
|
+
"List the table's foreign key constraints in the annotation") do
|
173
173
|
@options[:show_foreign_keys] = true
|
174
174
|
end
|
175
175
|
|
176
|
-
option_parser.on(
|
177
|
-
|
178
|
-
|
176
|
+
option_parser.on("--ck",
|
177
|
+
"--complete-foreign-keys",
|
178
|
+
"Complete foreign key names in the annotation") do
|
179
179
|
@options[:show_foreign_keys] = true
|
180
180
|
@options[:show_complete_foreign_keys] = true
|
181
181
|
end
|
182
182
|
|
183
|
-
option_parser.on(
|
184
|
-
|
185
|
-
|
183
|
+
option_parser.on("-i",
|
184
|
+
"--show-indexes",
|
185
|
+
"List the table's database indexes in the annotation") do
|
186
186
|
@options[:show_indexes] = true
|
187
187
|
end
|
188
188
|
|
189
|
-
option_parser.on(
|
190
|
-
|
191
|
-
|
189
|
+
option_parser.on("-s",
|
190
|
+
"--simple-indexes",
|
191
|
+
"Concat the column's related indexes in the annotation") do
|
192
192
|
@options[:simple_indexes] = true
|
193
193
|
end
|
194
194
|
|
195
|
-
option_parser.on(
|
196
|
-
|
195
|
+
option_parser.on("--hide-limit-column-types VALUES",
|
196
|
+
"don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
|
197
197
|
@options[:hide_limit_column_types] = values.to_s
|
198
198
|
end
|
199
199
|
|
200
|
-
option_parser.on(
|
201
|
-
|
200
|
+
option_parser.on("--hide-default-column-types VALUES",
|
201
|
+
"don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
|
202
202
|
@options[:hide_default_column_types] = values.to_s
|
203
203
|
end
|
204
204
|
|
205
|
-
option_parser.on(
|
206
|
-
|
205
|
+
option_parser.on("--ignore-unknown-models",
|
206
|
+
"don't display warnings for bad model files") do
|
207
207
|
@options[:ignore_unknown_models] = true
|
208
208
|
end
|
209
209
|
|
210
|
-
option_parser.on(
|
211
|
-
|
212
|
-
|
210
|
+
option_parser.on("-I",
|
211
|
+
"--ignore-columns REGEX",
|
212
|
+
"don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
|
213
213
|
@options[:ignore_columns] = regex
|
214
214
|
end
|
215
215
|
|
216
|
-
option_parser.on(
|
217
|
-
|
216
|
+
option_parser.on("--with-comment",
|
217
|
+
"include database comments in model annotations") do
|
218
218
|
@options[:with_comment] = true
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
222
|
def add_route_options_to_parser(option_parser)
|
223
|
-
option_parser.separator(
|
224
|
-
option_parser.separator(
|
225
|
-
option_parser.separator(
|
226
|
-
option_parser.separator(
|
223
|
+
option_parser.separator("")
|
224
|
+
option_parser.separator("Annotate routes options:")
|
225
|
+
option_parser.separator(" " * 4 + "Usage: annotaterb routes [options]")
|
226
|
+
option_parser.separator("")
|
227
227
|
|
228
|
-
option_parser.on(
|
229
|
-
|
228
|
+
option_parser.on("--ignore-routes REGEX",
|
229
|
+
"don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
|
230
230
|
@options[:ignore_routes] = regex
|
231
231
|
end
|
232
232
|
|
233
|
-
option_parser.on(
|
234
|
-
|
233
|
+
option_parser.on("--timestamp",
|
234
|
+
"Include timestamp in (routes) annotation") do
|
235
235
|
@options[:timestamp] = true
|
236
236
|
end
|
237
237
|
end
|
@@ -239,10 +239,10 @@ module AnnotateRb
|
|
239
239
|
def add_position_options_to_parser(option_parser)
|
240
240
|
has_set_position = {}
|
241
241
|
|
242
|
-
option_parser.on(
|
243
|
-
|
244
|
-
|
245
|
-
|
242
|
+
option_parser.on("-p",
|
243
|
+
"--position [before|top|after|bottom]",
|
244
|
+
ANNOTATION_POSITIONS,
|
245
|
+
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)") do |position|
|
246
246
|
@options[:position] = position
|
247
247
|
|
248
248
|
FILE_TYPE_POSITIONS.each do |key|
|
@@ -250,120 +250,128 @@ module AnnotateRb
|
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
|
-
option_parser.on(
|
254
|
-
|
255
|
-
|
256
|
-
|
253
|
+
option_parser.on("--pc",
|
254
|
+
"--position-in-class [before|top|after|bottom]",
|
255
|
+
ANNOTATION_POSITIONS,
|
256
|
+
"Place the annotations at the top (before) or the bottom (after) of the model file") do |position_in_class|
|
257
257
|
@options[:position_in_class] = position_in_class
|
258
|
-
has_set_position[
|
258
|
+
has_set_position["position_in_class"] = true
|
259
259
|
end
|
260
260
|
|
261
|
-
option_parser.on(
|
262
|
-
|
263
|
-
|
264
|
-
|
261
|
+
option_parser.on("--pf",
|
262
|
+
"--position-in-factory [before|top|after|bottom]",
|
263
|
+
ANNOTATION_POSITIONS,
|
264
|
+
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |position_in_factory|
|
265
265
|
@options[:position_in_factory] = position_in_factory
|
266
|
-
has_set_position[
|
266
|
+
has_set_position["position_in_factory"] = true
|
267
267
|
end
|
268
268
|
|
269
|
-
option_parser.on(
|
270
|
-
|
271
|
-
|
272
|
-
|
269
|
+
option_parser.on("--px",
|
270
|
+
"--position-in-fixture [before|top|after|bottom]",
|
271
|
+
ANNOTATION_POSITIONS,
|
272
|
+
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |position_in_fixture|
|
273
273
|
@options[:position_in_fixture] = position_in_fixture
|
274
|
-
has_set_position[
|
274
|
+
has_set_position["position_in_fixture"] = true
|
275
275
|
end
|
276
276
|
|
277
|
-
option_parser.on(
|
278
|
-
|
279
|
-
|
280
|
-
|
277
|
+
option_parser.on("--pt",
|
278
|
+
"--position-in-test [before|top|after|bottom]",
|
279
|
+
ANNOTATION_POSITIONS,
|
280
|
+
"Place the annotations at the top (before) or the bottom (after) of any test files") do |position_in_test|
|
281
281
|
@options[:position_in_test] = position_in_test
|
282
|
-
has_set_position[
|
282
|
+
has_set_position["position_in_test"] = true
|
283
283
|
end
|
284
284
|
|
285
|
-
option_parser.on(
|
286
|
-
|
287
|
-
|
288
|
-
|
285
|
+
option_parser.on("--pr",
|
286
|
+
"--position-in-routes [before|top|after|bottom]",
|
287
|
+
ANNOTATION_POSITIONS,
|
288
|
+
"Place the annotations at the top (before) or the bottom (after) of the routes.rb file") do |position_in_routes|
|
289
289
|
@options[:position_in_routes] = position_in_routes
|
290
|
-
has_set_position[
|
290
|
+
has_set_position["position_in_routes"] = true
|
291
291
|
end
|
292
292
|
|
293
|
-
option_parser.on(
|
294
|
-
|
295
|
-
|
296
|
-
|
293
|
+
option_parser.on("--ps",
|
294
|
+
"--position-in-serializer [before|top|after|bottom]",
|
295
|
+
ANNOTATION_POSITIONS,
|
296
|
+
"Place the annotations at the top (before) or the bottom (after) of the serializer files") do |position_in_serializer|
|
297
297
|
@options[:position_in_serializer] = position_in_serializer
|
298
|
-
has_set_position[
|
298
|
+
has_set_position["position_in_serializer"] = true
|
299
|
+
end
|
300
|
+
|
301
|
+
option_parser.on("--pa",
|
302
|
+
"--position-in-additional-file-patterns [before|top|after|bottom]",
|
303
|
+
ANNOTATION_POSITIONS,
|
304
|
+
"Place the annotations at the top (before) or the bottom (after) of files captured in additional file patterns") do |position_in_serializer|
|
305
|
+
@options[:position_in_additional_file_patterns] = position_in_serializer
|
306
|
+
has_set_position["position_in_additional_file_patterns"] = true
|
299
307
|
end
|
300
308
|
end
|
301
309
|
|
302
310
|
def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
|
303
|
-
option_parser.separator(
|
304
|
-
option_parser.separator(
|
305
|
-
option_parser.separator(
|
306
|
-
option_parser.separator(
|
307
|
-
|
308
|
-
option_parser.on(
|
309
|
-
|
310
|
-
|
311
|
+
option_parser.separator("")
|
312
|
+
option_parser.separator("Command options:")
|
313
|
+
option_parser.separator("Additional options that work for annotating models and routes")
|
314
|
+
option_parser.separator("")
|
315
|
+
|
316
|
+
option_parser.on("--additional-file-patterns path1,path2,path3",
|
317
|
+
Array,
|
318
|
+
"Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns|
|
311
319
|
@options[:additional_file_patterns] = additional_file_patterns
|
312
320
|
end
|
313
321
|
|
314
|
-
option_parser.on(
|
315
|
-
|
316
|
-
|
322
|
+
option_parser.on("-d",
|
323
|
+
"--delete",
|
324
|
+
"Remove annotations from all model files or the routes.rb file") do
|
317
325
|
@options[:target_action] = :remove_annotations
|
318
326
|
end
|
319
327
|
|
320
|
-
option_parser.on(
|
321
|
-
|
328
|
+
option_parser.on("--model-dir dir",
|
329
|
+
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
|
322
330
|
@options[:model_dir] = dir
|
323
331
|
end
|
324
332
|
|
325
|
-
option_parser.on(
|
326
|
-
|
333
|
+
option_parser.on("--root-dir dir",
|
334
|
+
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
|
327
335
|
@options[:root_dir] = dir
|
328
336
|
end
|
329
337
|
|
330
|
-
option_parser.on(
|
331
|
-
|
338
|
+
option_parser.on("--ignore-model-subdirects",
|
339
|
+
"Ignore subdirectories of the models directory") do
|
332
340
|
@options[:ignore_model_sub_dir] = true
|
333
341
|
end
|
334
342
|
|
335
|
-
option_parser.on(
|
336
|
-
|
343
|
+
option_parser.on("--sort",
|
344
|
+
"Sort columns alphabetically, rather than in creation order") do
|
337
345
|
@options[:sort] = true
|
338
346
|
end
|
339
347
|
|
340
|
-
option_parser.on(
|
341
|
-
|
348
|
+
option_parser.on("--classified-sort",
|
349
|
+
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do
|
342
350
|
@options[:classified_sort] = true
|
343
351
|
end
|
344
352
|
|
345
|
-
option_parser.on(
|
346
|
-
|
347
|
-
|
353
|
+
option_parser.on("-R",
|
354
|
+
"--require path",
|
355
|
+
"Additional file to require before loading models, may be used multiple times") do |path|
|
348
356
|
@options[:require] = if @options[:require].present?
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
357
|
+
[@options[:require], path].join(",")
|
358
|
+
else
|
359
|
+
path
|
360
|
+
end
|
353
361
|
end
|
354
362
|
|
355
|
-
option_parser.on(
|
356
|
-
|
357
|
-
|
358
|
-
|
363
|
+
option_parser.on("-e",
|
364
|
+
"--exclude [tests,fixtures,factories,serializers]",
|
365
|
+
Array,
|
366
|
+
"Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
|
359
367
|
exclusions ||= EXCLUSION_LIST
|
360
368
|
exclusions.each { |exclusion| @options["exclude_#{exclusion}".to_sym] = true }
|
361
369
|
end
|
362
370
|
|
363
|
-
option_parser.on(
|
364
|
-
|
365
|
-
|
366
|
-
|
371
|
+
option_parser.on("-f",
|
372
|
+
"--format [bare|rdoc|yard|markdown]",
|
373
|
+
FORMAT_TYPES,
|
374
|
+
"Render Schema Information as plain/RDoc/Yard/Markdown") do |format_type|
|
367
375
|
@options["format_#{format_type}".to_sym] = true
|
368
376
|
end
|
369
377
|
end
|
@@ -5,15 +5,15 @@ module AnnotateRb
|
|
5
5
|
class << self
|
6
6
|
def call(options)
|
7
7
|
begin
|
8
|
-
require
|
9
|
-
rescue
|
8
|
+
require "rake/dsl_definition"
|
9
|
+
rescue => e
|
10
10
|
# We might just be on an old version of Rake...
|
11
|
-
|
11
|
+
warn e.message
|
12
12
|
exit e.status_code
|
13
13
|
end
|
14
14
|
|
15
|
-
require
|
16
|
-
load
|
15
|
+
require "rake"
|
16
|
+
load "./Rakefile" if File.exist?("./Rakefile")
|
17
17
|
|
18
18
|
begin
|
19
19
|
Rake::Task[:environment].invoke
|
@@ -24,9 +24,9 @@ module AnnotateRb
|
|
24
24
|
unless defined?(Rails)
|
25
25
|
# Not in a Rails project, so time to load up the parts of
|
26
26
|
# ActiveSupport we need.
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
27
|
+
require "active_support"
|
28
|
+
require "active_support/core_ext/class/subclasses"
|
29
|
+
require "active_support/core_ext/string/inflections"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -5,7 +5,6 @@ module AnnotateRb
|
|
5
5
|
module RouteAnnotator
|
6
6
|
# This class is abstract class of classes adding and removing annotation to config/routes.rb.
|
7
7
|
class AnnotationProcessor < BaseProcessor
|
8
|
-
|
9
8
|
# @return [String]
|
10
9
|
def execute
|
11
10
|
if routes_file_exist?
|
@@ -27,30 +26,30 @@ module AnnotateRb
|
|
27
26
|
|
28
27
|
def generate_new_content_array(content, header_position)
|
29
28
|
magic_comments_map, content = Helper.extract_magic_comments_from_array(content)
|
30
|
-
if %w
|
29
|
+
if %w[before top].include?(options[:position_in_routes])
|
31
30
|
new_content_array = []
|
32
31
|
new_content_array += magic_comments_map
|
33
|
-
new_content_array <<
|
32
|
+
new_content_array << "" if magic_comments_map.any?
|
34
33
|
new_content_array += header
|
35
|
-
new_content_array <<
|
34
|
+
new_content_array << "" if content.first != ""
|
36
35
|
new_content_array += content
|
37
36
|
else
|
38
37
|
# Ensure we have adequate trailing newlines at the end of the file to
|
39
38
|
# ensure a blank line separating the content from the annotation.
|
40
|
-
content <<
|
39
|
+
content << "" unless content.last == ""
|
41
40
|
|
42
41
|
# We're moving something from the top of the file to the bottom, so ditch
|
43
42
|
# the spacer we put in the first time around.
|
44
|
-
content.shift if header_position == :before && content.first ==
|
43
|
+
content.shift if header_position == :before && content.first == ""
|
45
44
|
|
46
45
|
new_content_array = magic_comments_map + content + header
|
47
46
|
end
|
48
47
|
|
49
48
|
# Make sure we end on a trailing newline.
|
50
|
-
new_content_array <<
|
49
|
+
new_content_array << "" unless new_content_array.last == ""
|
51
50
|
|
52
51
|
new_content_array
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
56
|
-
end
|
55
|
+
end
|
@@ -23,14 +23,14 @@ module AnnotateRb
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def add_annotations
|
26
|
-
routes_file = File.join(
|
26
|
+
routes_file = File.join("config", "routes.rb")
|
27
27
|
AnnotationProcessor.execute(@options, routes_file).tap do |result|
|
28
28
|
puts result
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def remove_annotations
|
33
|
-
routes_file = File.join(
|
33
|
+
routes_file = File.join("config", "routes.rb")
|
34
34
|
RemovalProcessor.execute(@options, routes_file).tap do |result|
|
35
35
|
puts result
|
36
36
|
end
|
@@ -55,7 +55,7 @@ module AnnotateRb
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def write(text)
|
58
|
-
File.open(routes_file,
|
58
|
+
File.open(routes_file, "wb") { |f| f.puts(text) }
|
59
59
|
end
|
60
60
|
|
61
61
|
# TODO: write the method doc using ruby rdoc formats
|
@@ -75,7 +75,7 @@ module AnnotateRb
|
|
75
75
|
mode = :content
|
76
76
|
real_content << line unless line.blank?
|
77
77
|
elsif mode == :content
|
78
|
-
if
|
78
|
+
if /^\s*#\s*== Route.*$/.match?(line)
|
79
79
|
header_position = line_number + 1 # index start's at 0
|
80
80
|
mode = :header
|
81
81
|
else
|
@@ -97,7 +97,7 @@ module AnnotateRb
|
|
97
97
|
return real_content, :after if header_position >= real_content.count
|
98
98
|
|
99
99
|
# and the default
|
100
|
-
|
100
|
+
[real_content, header_position]
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|