annotate 3.0.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{AUTHORS.rdoc → AUTHORS.md} +2 -2
- data/CHANGELOG.md +326 -0
- data/{README.rdoc → README.md} +139 -105
- data/RELEASE.md +19 -0
- data/annotate.gemspec +11 -28
- data/bin/annotate +3 -3
- data/lib/annotate/annotate_models/file_patterns.rb +127 -0
- data/lib/annotate/annotate_models.rb +156 -181
- data/lib/annotate/annotate_routes/header_generator.rb +113 -0
- data/lib/annotate/annotate_routes/helpers.rb +69 -0
- data/lib/annotate/annotate_routes.rb +44 -177
- data/lib/annotate/constants.rb +33 -0
- data/lib/annotate/helpers.rb +30 -0
- data/lib/annotate/parser.rb +127 -75
- data/lib/annotate/version.rb +1 -1
- data/lib/annotate.rb +21 -80
- data/lib/generators/annotate/templates/auto_annotate_models.rake +3 -1
- data/lib/tasks/annotate_models.rake +36 -35
- data/lib/tasks/annotate_models_migrate.rake +17 -4
- data/lib/tasks/annotate_routes.rake +12 -6
- data/potato.md +41 -0
- metadata +23 -18
- data/CHANGELOG.rdoc +0 -238
- data/TODO.rdoc +0 -11
data/lib/annotate/parser.rb
CHANGED
@@ -9,14 +9,19 @@ module Annotate
|
|
9
9
|
|
10
10
|
attr_reader :args, :options, :env
|
11
11
|
|
12
|
+
DEFAULT_OPTIONS = {
|
13
|
+
target_action: :do_annotations,
|
14
|
+
exit: false
|
15
|
+
}.freeze
|
16
|
+
|
12
17
|
ANNOTATION_POSITIONS = %w[before top after bottom].freeze
|
13
18
|
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
|
14
19
|
EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
|
15
|
-
FORMAT_TYPES = %w[bare rdoc markdown].freeze
|
20
|
+
FORMAT_TYPES = %w[bare rdoc yard markdown].freeze
|
16
21
|
|
17
22
|
def initialize(args, env)
|
18
23
|
@args = args
|
19
|
-
@options =
|
24
|
+
@options = DEFAULT_OPTIONS.dup
|
20
25
|
@env = env
|
21
26
|
end
|
22
27
|
|
@@ -31,128 +36,164 @@ module Annotate
|
|
31
36
|
|
32
37
|
private
|
33
38
|
|
34
|
-
def commit
|
35
|
-
env.each_pair do |key, value|
|
36
|
-
ENV[key] = value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
39
|
def parser
|
41
40
|
OptionParser.new do |option_parser|
|
42
41
|
add_options_to_parser(option_parser)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
45
|
+
def commit
|
46
|
+
env.each_pair do |key, value|
|
47
|
+
ENV[key] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
46
51
|
def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
|
47
52
|
has_set_position = {}
|
48
|
-
positions = ANNOTATION_POSITIONS
|
49
53
|
|
50
54
|
option_parser.banner = 'Usage: annotate [options] [model_file]*'
|
51
55
|
|
52
|
-
option_parser.on('--additional-file-patterns path1,path2,path3',
|
56
|
+
option_parser.on('--additional-file-patterns path1,path2,path3',
|
57
|
+
Array,
|
58
|
+
"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|
|
53
59
|
ENV['additional_file_patterns'] = additional_file_patterns
|
54
60
|
end
|
55
61
|
|
56
|
-
option_parser.on('-d',
|
62
|
+
option_parser.on('-d',
|
63
|
+
'--delete',
|
64
|
+
'Remove annotations from all model files or the routes.rb file') do
|
57
65
|
@options[:target_action] = :remove_annotations
|
58
66
|
end
|
59
67
|
|
60
|
-
option_parser.on('-p',
|
61
|
-
'
|
62
|
-
|
68
|
+
option_parser.on('-p',
|
69
|
+
'--position [before|top|after|bottom]',
|
70
|
+
ANNOTATION_POSITIONS,
|
71
|
+
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |position|
|
72
|
+
env['position'] = position
|
63
73
|
|
64
74
|
FILE_TYPE_POSITIONS.each do |key|
|
65
|
-
env[key] =
|
75
|
+
env[key] = position unless has_set_position[key]
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
option_parser.on('--pc',
|
70
|
-
'
|
71
|
-
|
79
|
+
option_parser.on('--pc',
|
80
|
+
'--position-in-class [before|top|after|bottom]',
|
81
|
+
ANNOTATION_POSITIONS,
|
82
|
+
'Place the annotations at the top (before) or the bottom (after) of the model file') do |position_in_class|
|
83
|
+
env['position_in_class'] = position_in_class
|
72
84
|
has_set_position['position_in_class'] = true
|
73
85
|
end
|
74
86
|
|
75
|
-
option_parser.on('--pf',
|
76
|
-
'
|
77
|
-
|
87
|
+
option_parser.on('--pf',
|
88
|
+
'--position-in-factory [before|top|after|bottom]',
|
89
|
+
ANNOTATION_POSITIONS,
|
90
|
+
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |position_in_factory|
|
91
|
+
env['position_in_factory'] = position_in_factory
|
78
92
|
has_set_position['position_in_factory'] = true
|
79
93
|
end
|
80
94
|
|
81
|
-
option_parser.on('--px',
|
82
|
-
'
|
83
|
-
|
95
|
+
option_parser.on('--px',
|
96
|
+
'--position-in-fixture [before|top|after|bottom]',
|
97
|
+
ANNOTATION_POSITIONS,
|
98
|
+
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |position_in_fixture|
|
99
|
+
env['position_in_fixture'] = position_in_fixture
|
84
100
|
has_set_position['position_in_fixture'] = true
|
85
101
|
end
|
86
102
|
|
87
|
-
option_parser.on('--pt',
|
88
|
-
'
|
89
|
-
|
103
|
+
option_parser.on('--pt',
|
104
|
+
'--position-in-test [before|top|after|bottom]',
|
105
|
+
ANNOTATION_POSITIONS,
|
106
|
+
'Place the annotations at the top (before) or the bottom (after) of any test files') do |position_in_test|
|
107
|
+
env['position_in_test'] = position_in_test
|
90
108
|
has_set_position['position_in_test'] = true
|
91
109
|
end
|
92
110
|
|
93
|
-
option_parser.on('--pr',
|
94
|
-
'
|
95
|
-
|
111
|
+
option_parser.on('--pr',
|
112
|
+
'--position-in-routes [before|top|after|bottom]',
|
113
|
+
ANNOTATION_POSITIONS,
|
114
|
+
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |position_in_routes|
|
115
|
+
env['position_in_routes'] = position_in_routes
|
96
116
|
has_set_position['position_in_routes'] = true
|
97
117
|
end
|
98
118
|
|
99
|
-
option_parser.on('--ps',
|
100
|
-
'
|
101
|
-
|
119
|
+
option_parser.on('--ps',
|
120
|
+
'--position-in-serializer [before|top|after|bottom]',
|
121
|
+
ANNOTATION_POSITIONS,
|
122
|
+
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |position_in_serializer|
|
123
|
+
env['position_in_serializer'] = position_in_serializer
|
102
124
|
has_set_position['position_in_serializer'] = true
|
103
125
|
end
|
104
126
|
|
105
|
-
option_parser.on('--w',
|
106
|
-
'
|
107
|
-
|
127
|
+
option_parser.on('--w',
|
128
|
+
'--wrapper STR',
|
129
|
+
'Wrap annotation with the text passed as parameter.',
|
130
|
+
'If --w option is used, the same text will be used as opening and closing') do |wrapper|
|
131
|
+
env['wrapper'] = wrapper
|
108
132
|
end
|
109
133
|
|
110
|
-
option_parser.on('--wo',
|
111
|
-
|
134
|
+
option_parser.on('--wo',
|
135
|
+
'--wrapper-open STR',
|
136
|
+
'Annotation wrapper opening.') do |wrapper_open|
|
137
|
+
env['wrapper_open'] = wrapper_open
|
112
138
|
end
|
113
139
|
|
114
|
-
option_parser.on('--wc',
|
115
|
-
|
140
|
+
option_parser.on('--wc',
|
141
|
+
'--wrapper-close STR',
|
142
|
+
'Annotation wrapper closing') do |wrapper_close|
|
143
|
+
env['wrapper_close'] = wrapper_close
|
116
144
|
end
|
117
145
|
|
118
|
-
option_parser.on('-r',
|
146
|
+
option_parser.on('-r',
|
147
|
+
'--routes',
|
148
|
+
"Annotate routes.rb with the output of 'rake routes'") do
|
119
149
|
env['routes'] = 'true'
|
120
150
|
end
|
121
151
|
|
122
|
-
option_parser.on('--models',
|
152
|
+
option_parser.on('--models',
|
153
|
+
"Annotate ActiveRecord models") do
|
123
154
|
env['models'] = 'true'
|
124
155
|
end
|
125
156
|
|
126
|
-
option_parser.on('-a',
|
157
|
+
option_parser.on('-a',
|
158
|
+
'--active-admin',
|
159
|
+
'Annotate active_admin models') do
|
127
160
|
env['active_admin'] = 'true'
|
128
161
|
end
|
129
162
|
|
130
|
-
option_parser.on('-v',
|
163
|
+
option_parser.on('-v',
|
164
|
+
'--version',
|
165
|
+
'Show the current version of this gem') do
|
131
166
|
puts "annotate v#{Annotate.version}"
|
132
167
|
@options[:exit] = true
|
133
168
|
end
|
134
169
|
|
135
|
-
option_parser.on('-m',
|
170
|
+
option_parser.on('-m',
|
171
|
+
'--show-migration',
|
172
|
+
'Include the migration version number in the annotation') do
|
136
173
|
env['include_version'] = 'yes'
|
137
174
|
end
|
138
175
|
|
139
|
-
option_parser.on('-k',
|
176
|
+
option_parser.on('-k',
|
177
|
+
'--show-foreign-keys',
|
140
178
|
"List the table's foreign key constraints in the annotation") do
|
141
179
|
env['show_foreign_keys'] = 'yes'
|
142
180
|
end
|
143
181
|
|
144
182
|
option_parser.on('--ck',
|
145
|
-
'--complete-foreign-keys',
|
183
|
+
'--complete-foreign-keys',
|
184
|
+
'Complete foreign key names in the annotation') do
|
146
185
|
env['show_foreign_keys'] = 'yes'
|
147
186
|
env['show_complete_foreign_keys'] = 'yes'
|
148
187
|
end
|
149
188
|
|
150
|
-
option_parser.on('-i',
|
189
|
+
option_parser.on('-i',
|
190
|
+
'--show-indexes',
|
151
191
|
"List the table's database indexes in the annotation") do
|
152
192
|
env['show_indexes'] = 'yes'
|
153
193
|
end
|
154
194
|
|
155
|
-
option_parser.on('-s',
|
195
|
+
option_parser.on('-s',
|
196
|
+
'--simple-indexes',
|
156
197
|
"Concat the column's related indexes in the annotation") do
|
157
198
|
env['simple_indexes'] = 'yes'
|
158
199
|
end
|
@@ -168,84 +209,95 @@ module Annotate
|
|
168
209
|
end
|
169
210
|
|
170
211
|
option_parser.on('--ignore-model-subdirects',
|
171
|
-
"Ignore subdirectories of the models directory") do
|
212
|
+
"Ignore subdirectories of the models directory") do
|
172
213
|
env['ignore_model_sub_dir'] = 'yes'
|
173
214
|
end
|
174
215
|
|
175
216
|
option_parser.on('--sort',
|
176
|
-
"Sort columns alphabetically, rather than in creation order") do
|
217
|
+
"Sort columns alphabetically, rather than in creation order") do
|
177
218
|
env['sort'] = 'yes'
|
178
219
|
end
|
179
220
|
|
180
221
|
option_parser.on('--classified-sort',
|
181
|
-
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do
|
222
|
+
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do
|
182
223
|
env['classified_sort'] = 'yes'
|
183
224
|
end
|
184
225
|
|
185
|
-
option_parser.on('-R',
|
226
|
+
option_parser.on('-R',
|
227
|
+
'--require path',
|
186
228
|
"Additional file to require before loading models, may be used multiple times") do |path|
|
187
|
-
env['require'] = if
|
188
|
-
env['require']
|
229
|
+
env['require'] = if env['require'].present?
|
230
|
+
"#{env['require']},#{path}"
|
189
231
|
else
|
190
232
|
path
|
191
233
|
end
|
192
234
|
end
|
193
235
|
|
194
|
-
option_parser.on('-e',
|
236
|
+
option_parser.on('-e',
|
237
|
+
'--exclude [tests,fixtures,factories,serializers]',
|
238
|
+
Array,
|
239
|
+
"Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
|
195
240
|
exclusions ||= EXCLUSION_LIST
|
196
241
|
exclusions.each { |exclusion| env["exclude_#{exclusion}"] = 'yes' }
|
197
242
|
end
|
198
243
|
|
199
|
-
option_parser.on('-f',
|
200
|
-
|
244
|
+
option_parser.on('-f',
|
245
|
+
'--format [bare|rdoc|yard|markdown]',
|
246
|
+
FORMAT_TYPES,
|
247
|
+
'Render Schema Infomation as plain/RDoc/Yard/Markdown') do |format_type|
|
248
|
+
env["format_#{format_type}"] = 'yes'
|
201
249
|
end
|
202
250
|
|
203
|
-
option_parser.on('--force',
|
251
|
+
option_parser.on('--force',
|
252
|
+
'Force new annotations even if there are no changes.') do
|
204
253
|
env['force'] = 'yes'
|
205
254
|
end
|
206
255
|
|
207
|
-
option_parser.on('--frozen',
|
256
|
+
option_parser.on('--frozen',
|
257
|
+
'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
|
208
258
|
env['frozen'] = 'yes'
|
209
259
|
end
|
210
260
|
|
211
|
-
option_parser.on('--timestamp',
|
261
|
+
option_parser.on('--timestamp',
|
262
|
+
'Include timestamp in (routes) annotation') do
|
212
263
|
env['timestamp'] = 'true'
|
213
264
|
end
|
214
265
|
|
215
|
-
option_parser.on('--trace',
|
266
|
+
option_parser.on('--trace',
|
267
|
+
'If unable to annotate a file, print the full stack trace, not just the exception message.') do
|
216
268
|
env['trace'] = 'yes'
|
217
269
|
end
|
218
270
|
|
219
|
-
option_parser.on('-I',
|
271
|
+
option_parser.on('-I',
|
272
|
+
'--ignore-columns REGEX',
|
273
|
+
"don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
|
220
274
|
env['ignore_columns'] = regex
|
221
275
|
end
|
222
276
|
|
223
|
-
option_parser.on('--ignore-routes REGEX',
|
277
|
+
option_parser.on('--ignore-routes REGEX',
|
278
|
+
"don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
|
224
279
|
env['ignore_routes'] = regex
|
225
280
|
end
|
226
281
|
|
227
|
-
option_parser.on('--hide-limit-column-types VALUES',
|
282
|
+
option_parser.on('--hide-limit-column-types VALUES',
|
283
|
+
"don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
|
228
284
|
env['hide_limit_column_types'] = values.to_s
|
229
285
|
end
|
230
286
|
|
231
|
-
option_parser.on('--hide-default-column-types VALUES',
|
287
|
+
option_parser.on('--hide-default-column-types VALUES',
|
288
|
+
"don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
|
232
289
|
env['hide_default_column_types'] = values.to_s
|
233
290
|
end
|
234
291
|
|
235
|
-
option_parser.on('--ignore-unknown-models',
|
292
|
+
option_parser.on('--ignore-unknown-models',
|
293
|
+
"don't display warnings for bad model files") do
|
236
294
|
env['ignore_unknown_models'] = 'true'
|
237
295
|
end
|
238
296
|
|
239
|
-
option_parser.on('--with-comment',
|
297
|
+
option_parser.on('--with-comment',
|
298
|
+
"include database comments in model annotations") do
|
240
299
|
env['with_comment'] = 'true'
|
241
300
|
end
|
242
301
|
end
|
243
|
-
|
244
|
-
def default_options
|
245
|
-
{
|
246
|
-
target_action: :do_annotations,
|
247
|
-
exit: false
|
248
|
-
}
|
249
|
-
end
|
250
302
|
end
|
251
303
|
end
|
data/lib/annotate/version.rb
CHANGED
data/lib/annotate.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
# rubocop:disable Metrics/ModuleLength
|
2
|
-
|
3
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
2
|
require 'annotate/version'
|
5
3
|
require 'annotate/annotate_models'
|
6
4
|
require 'annotate/annotate_routes'
|
7
5
|
require 'annotate/constants'
|
6
|
+
require 'annotate/helpers'
|
8
7
|
|
9
8
|
begin
|
10
9
|
# ActiveSupport 3.x...
|
@@ -17,36 +16,6 @@ rescue StandardError
|
|
17
16
|
end
|
18
17
|
|
19
18
|
module Annotate
|
20
|
-
##
|
21
|
-
# The set of available options to customize the behavior of Annotate.
|
22
|
-
#
|
23
|
-
POSITION_OPTIONS = [
|
24
|
-
:position_in_routes, :position_in_class, :position_in_test,
|
25
|
-
:position_in_fixture, :position_in_factory, :position,
|
26
|
-
:position_in_serializer
|
27
|
-
].freeze
|
28
|
-
FLAG_OPTIONS = [
|
29
|
-
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
|
30
|
-
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
|
31
|
-
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :frozen,
|
32
|
-
:trace, :timestamp, :exclude_serializers, :classified_sort,
|
33
|
-
:show_foreign_keys, :show_complete_foreign_keys,
|
34
|
-
:exclude_scaffolds, :exclude_controllers, :exclude_helpers,
|
35
|
-
:exclude_sti_subclasses, :ignore_unknown_models, :with_comment
|
36
|
-
].freeze
|
37
|
-
OTHER_OPTIONS = [
|
38
|
-
:additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close,
|
39
|
-
:wrapper, :routes, :models, :hide_limit_column_types, :hide_default_column_types,
|
40
|
-
:ignore_routes, :active_admin
|
41
|
-
].freeze
|
42
|
-
PATH_OPTIONS = [
|
43
|
-
:require, :model_dir, :root_dir
|
44
|
-
].freeze
|
45
|
-
|
46
|
-
def self.all_options
|
47
|
-
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS]
|
48
|
-
end
|
49
|
-
|
50
19
|
##
|
51
20
|
# Set default values that can be overridden via environment variables.
|
52
21
|
#
|
@@ -54,9 +23,9 @@ module Annotate
|
|
54
23
|
return if @has_set_defaults
|
55
24
|
@has_set_defaults = true
|
56
25
|
|
57
|
-
options = HashWithIndifferentAccess.new(options)
|
26
|
+
options = ActiveSupport::HashWithIndifferentAccess.new(options)
|
58
27
|
|
59
|
-
|
28
|
+
Constants::ALL_ANNOTATE_OPTIONS.flatten.each do |key|
|
60
29
|
if options.key?(key)
|
61
30
|
default_value = if options[key].is_a?(Array)
|
62
31
|
options[key].join(',')
|
@@ -74,69 +43,42 @@ module Annotate
|
|
74
43
|
# TODO: what is the difference between this and set_defaults?
|
75
44
|
#
|
76
45
|
def self.setup_options(options = {})
|
77
|
-
POSITION_OPTIONS.each do |key|
|
78
|
-
options[key] = fallback(ENV[key.to_s], ENV['position'], 'before')
|
46
|
+
Constants::POSITION_OPTIONS.each do |key|
|
47
|
+
options[key] = Annotate::Helpers.fallback(ENV[key.to_s], ENV['position'], 'before')
|
79
48
|
end
|
80
|
-
FLAG_OPTIONS.each do |key|
|
81
|
-
options[key] = true?(ENV[key.to_s])
|
49
|
+
Constants::FLAG_OPTIONS.each do |key|
|
50
|
+
options[key] = Annotate::Helpers.true?(ENV[key.to_s])
|
82
51
|
end
|
83
|
-
OTHER_OPTIONS.each do |key|
|
52
|
+
Constants::OTHER_OPTIONS.each do |key|
|
84
53
|
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s] : nil
|
85
54
|
end
|
86
|
-
PATH_OPTIONS.each do |key|
|
55
|
+
Constants::PATH_OPTIONS.each do |key|
|
87
56
|
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : []
|
88
57
|
end
|
89
58
|
|
90
59
|
options[:additional_file_patterns] ||= []
|
60
|
+
options[:additional_file_patterns] = options[:additional_file_patterns].split(',') if options[:additional_file_patterns].is_a?(String)
|
91
61
|
options[:model_dir] = ['app/models'] if options[:model_dir].empty?
|
92
62
|
|
93
63
|
options[:wrapper_open] ||= options[:wrapper]
|
94
64
|
options[:wrapper_close] ||= options[:wrapper]
|
95
65
|
|
96
66
|
# These were added in 2.7.0 but so this is to revert to old behavior by default
|
97
|
-
options[:exclude_scaffolds] = Annotate.true?(ENV.fetch('exclude_scaffolds', 'true'))
|
98
|
-
options[:exclude_controllers] = Annotate.true?(ENV.fetch('exclude_controllers', 'true'))
|
99
|
-
options[:exclude_helpers] = Annotate.true?(ENV.fetch('exclude_helpers', 'true'))
|
67
|
+
options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV.fetch('exclude_scaffolds', 'true'))
|
68
|
+
options[:exclude_controllers] = Annotate::Helpers.true?(ENV.fetch('exclude_controllers', 'true'))
|
69
|
+
options[:exclude_helpers] = Annotate::Helpers.true?(ENV.fetch('exclude_helpers', 'true'))
|
100
70
|
|
101
71
|
options
|
102
72
|
end
|
103
73
|
|
104
|
-
def self.reset_options
|
105
|
-
all_options.flatten.each { |key| ENV[key.to_s] = nil }
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.skip_on_migration?
|
109
|
-
ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.include_routes?
|
113
|
-
ENV['routes'] =~ Constants::TRUE_RE
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.include_models?
|
117
|
-
ENV['models'] =~ Constants::TRUE_RE
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.loaded_tasks=(val)
|
121
|
-
@loaded_tasks = val
|
122
|
-
end
|
123
|
-
|
124
|
-
def self.loaded_tasks
|
125
|
-
@loaded_tasks
|
126
|
-
end
|
127
|
-
|
128
74
|
def self.load_tasks
|
129
|
-
return if
|
130
|
-
self.loaded_tasks = true
|
75
|
+
return if @tasks_loaded
|
131
76
|
|
132
77
|
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each do |rake|
|
133
78
|
load rake
|
134
79
|
end
|
135
|
-
end
|
136
80
|
|
137
|
-
|
138
|
-
options[:require].count > 0 &&
|
139
|
-
options[:require].each { |path| require path }
|
81
|
+
@tasks_loaded = true
|
140
82
|
end
|
141
83
|
|
142
84
|
def self.eager_load(options)
|
@@ -192,13 +134,12 @@ module Annotate
|
|
192
134
|
Rake::Task[:set_annotation_options].invoke
|
193
135
|
end
|
194
136
|
|
195
|
-
|
196
|
-
|
197
|
-
end
|
137
|
+
class << self
|
138
|
+
private
|
198
139
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
140
|
+
def load_requires(options)
|
141
|
+
options[:require].count > 0 &&
|
142
|
+
options[:require].each { |path| require path }
|
143
|
+
end
|
203
144
|
end
|
204
145
|
end
|
@@ -7,9 +7,10 @@ if Rails.env.development?
|
|
7
7
|
# You can override any of these by setting an environment variable of the
|
8
8
|
# same name.
|
9
9
|
Annotate.set_defaults(
|
10
|
+
'active_admin' => 'false',
|
10
11
|
'additional_file_patterns' => [],
|
11
12
|
'routes' => 'false',
|
12
|
-
'models' => '
|
13
|
+
'models' => 'true',
|
13
14
|
'position_in_routes' => 'before',
|
14
15
|
'position_in_class' => 'before',
|
15
16
|
'position_in_test' => 'before',
|
@@ -41,6 +42,7 @@ if Rails.env.development?
|
|
41
42
|
'skip_on_db_migrate' => 'false',
|
42
43
|
'format_bare' => 'true',
|
43
44
|
'format_rdoc' => 'false',
|
45
|
+
'format_yard' => 'false',
|
44
46
|
'format_markdown' => 'false',
|
45
47
|
'sort' => 'false',
|
46
48
|
'force' => 'false',
|
@@ -11,46 +11,47 @@ task annotate_models: :environment do
|
|
11
11
|
require "#{annotate_lib}/annotate/active_record_patch"
|
12
12
|
|
13
13
|
options = {is_rake: true}
|
14
|
-
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
|
14
|
+
ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV['position'], 'before')
|
15
15
|
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
|
16
|
-
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
|
17
|
-
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
|
18
|
-
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
|
19
|
-
options[:position_in_test] = Annotate.fallback(ENV['position_in_test'], ENV['position'])
|
20
|
-
options[:position_in_serializer] = Annotate.fallback(ENV['position_in_serializer'], ENV['position'])
|
21
|
-
options[:show_foreign_keys] = Annotate.true?(ENV['show_foreign_keys'])
|
22
|
-
options[:show_complete_foreign_keys] = Annotate.true?(ENV['show_complete_foreign_keys'])
|
23
|
-
options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
|
24
|
-
options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
|
16
|
+
options[:position_in_class] = Annotate::Helpers.fallback(ENV['position_in_class'], ENV['position'])
|
17
|
+
options[:position_in_fixture] = Annotate::Helpers.fallback(ENV['position_in_fixture'], ENV['position'])
|
18
|
+
options[:position_in_factory] = Annotate::Helpers.fallback(ENV['position_in_factory'], ENV['position'])
|
19
|
+
options[:position_in_test] = Annotate::Helpers.fallback(ENV['position_in_test'], ENV['position'])
|
20
|
+
options[:position_in_serializer] = Annotate::Helpers.fallback(ENV['position_in_serializer'], ENV['position'])
|
21
|
+
options[:show_foreign_keys] = Annotate::Helpers.true?(ENV['show_foreign_keys'])
|
22
|
+
options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV['show_complete_foreign_keys'])
|
23
|
+
options[:show_indexes] = Annotate::Helpers.true?(ENV['show_indexes'])
|
24
|
+
options[:simple_indexes] = Annotate::Helpers.true?(ENV['simple_indexes'])
|
25
25
|
options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models']
|
26
26
|
options[:root_dir] = ENV['root_dir']
|
27
|
-
options[:include_version] = Annotate.true?(ENV['include_version'])
|
27
|
+
options[:include_version] = Annotate::Helpers.true?(ENV['include_version'])
|
28
28
|
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
29
|
-
options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
|
30
|
-
options[:exclude_factories] = Annotate.true?(ENV['exclude_factories'])
|
31
|
-
options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
|
32
|
-
options[:exclude_serializers] = Annotate.true?(ENV['exclude_serializers'])
|
33
|
-
options[:exclude_scaffolds] = Annotate.true?(ENV['exclude_scaffolds'])
|
34
|
-
options[:exclude_controllers] = Annotate.true?(ENV.fetch('exclude_controllers', 'true'))
|
35
|
-
options[:exclude_helpers] = Annotate.true?(ENV.fetch('exclude_helpers', 'true'))
|
36
|
-
options[:exclude_sti_subclasses] = Annotate.true?(ENV['exclude_sti_subclasses'])
|
37
|
-
options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
|
38
|
-
options[:format_bare] = Annotate.true?(ENV['format_bare'])
|
39
|
-
options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
|
40
|
-
options[:
|
41
|
-
options[:
|
42
|
-
options[:
|
43
|
-
options[:
|
44
|
-
options[:
|
45
|
-
options[:
|
46
|
-
options[:
|
47
|
-
options[:
|
29
|
+
options[:exclude_tests] = Annotate::Helpers.true?(ENV['exclude_tests'])
|
30
|
+
options[:exclude_factories] = Annotate::Helpers.true?(ENV['exclude_factories'])
|
31
|
+
options[:exclude_fixtures] = Annotate::Helpers.true?(ENV['exclude_fixtures'])
|
32
|
+
options[:exclude_serializers] = Annotate::Helpers.true?(ENV['exclude_serializers'])
|
33
|
+
options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV['exclude_scaffolds'])
|
34
|
+
options[:exclude_controllers] = Annotate::Helpers.true?(ENV.fetch('exclude_controllers', 'true'))
|
35
|
+
options[:exclude_helpers] = Annotate::Helpers.true?(ENV.fetch('exclude_helpers', 'true'))
|
36
|
+
options[:exclude_sti_subclasses] = Annotate::Helpers.true?(ENV['exclude_sti_subclasses'])
|
37
|
+
options[:ignore_model_sub_dir] = Annotate::Helpers.true?(ENV['ignore_model_sub_dir'])
|
38
|
+
options[:format_bare] = Annotate::Helpers.true?(ENV['format_bare'])
|
39
|
+
options[:format_rdoc] = Annotate::Helpers.true?(ENV['format_rdoc'])
|
40
|
+
options[:format_yard] = Annotate::Helpers.true?(ENV['format_yard'])
|
41
|
+
options[:format_markdown] = Annotate::Helpers.true?(ENV['format_markdown'])
|
42
|
+
options[:sort] = Annotate::Helpers.true?(ENV['sort'])
|
43
|
+
options[:force] = Annotate::Helpers.true?(ENV['force'])
|
44
|
+
options[:frozen] = Annotate::Helpers.true?(ENV['frozen'])
|
45
|
+
options[:classified_sort] = Annotate::Helpers.true?(ENV['classified_sort'])
|
46
|
+
options[:trace] = Annotate::Helpers.true?(ENV['trace'])
|
47
|
+
options[:wrapper_open] = Annotate::Helpers.fallback(ENV['wrapper_open'], ENV['wrapper'])
|
48
|
+
options[:wrapper_close] = Annotate::Helpers.fallback(ENV['wrapper_close'], ENV['wrapper'])
|
48
49
|
options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
|
49
50
|
options[:ignore_routes] = ENV.fetch('ignore_routes', nil)
|
50
|
-
options[:hide_limit_column_types] = Annotate.fallback(ENV['hide_limit_column_types'], '')
|
51
|
-
options[:hide_default_column_types] = Annotate.fallback(ENV['hide_default_column_types'], '')
|
52
|
-
options[:with_comment] = Annotate.true?(ENV['with_comment'])
|
53
|
-
options[:ignore_unknown_models] = Annotate.true?(ENV.fetch('ignore_unknown_models', 'false'))
|
51
|
+
options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV['hide_limit_column_types'], '')
|
52
|
+
options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV['hide_default_column_types'], '')
|
53
|
+
options[:with_comment] = Annotate::Helpers.true?(ENV['with_comment'])
|
54
|
+
options[:ignore_unknown_models] = Annotate::Helpers.true?(ENV.fetch('ignore_unknown_models', 'false'))
|
54
55
|
|
55
56
|
AnnotateModels.do_annotations(options)
|
56
57
|
end
|
@@ -64,6 +65,6 @@ task remove_annotation: :environment do
|
|
64
65
|
options[:model_dir] = ENV['model_dir']
|
65
66
|
options[:root_dir] = ENV['root_dir']
|
66
67
|
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
|
67
|
-
options[:trace] = Annotate.true?(ENV['trace'])
|
68
|
+
options[:trace] = Annotate::Helpers.true?(ENV['trace'])
|
68
69
|
AnnotateModels.remove_annotations(options)
|
69
70
|
end
|