annotate 2.6.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/{AUTHORS.rdoc → AUTHORS.md} +3 -2
- data/CHANGELOG.md +326 -0
- data/README.md +331 -0
- data/RELEASE.md +19 -0
- data/annotate.gemspec +26 -33
- data/bin/annotate +17 -133
- data/lib/annotate/active_record_patch.rb +1 -1
- data/lib/annotate/annotate_models/file_patterns.rb +127 -0
- data/lib/annotate/annotate_models.rb +736 -287
- 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 +80 -109
- data/lib/annotate/constants.rb +38 -0
- data/lib/annotate/helpers.rb +30 -0
- data/lib/annotate/parser.rb +303 -0
- data/lib/annotate/version.rb +1 -1
- data/lib/annotate.rb +72 -77
- data/lib/generators/annotate/install_generator.rb +5 -4
- data/lib/generators/annotate/templates/auto_annotate_models.rake +49 -24
- data/lib/tasks/annotate_models.rake +51 -28
- data/lib/tasks/annotate_models_migrate.rake +63 -0
- data/lib/tasks/annotate_routes.rake +12 -3
- data/potato.md +41 -0
- metadata +45 -28
- data/.travis.yml +0 -6
- data/CHANGELOG.rdoc +0 -175
- data/README.rdoc +0 -246
- data/TODO.rdoc +0 -12
- data/lib/tasks/migrate.rake +0 -33
@@ -0,0 +1,303 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Annotate
|
4
|
+
# Class for handling command line arguments
|
5
|
+
class Parser # rubocop:disable Metrics/ClassLength
|
6
|
+
def self.parse(args, env = {})
|
7
|
+
new(args, env).parse
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :args, :options, :env
|
11
|
+
|
12
|
+
DEFAULT_OPTIONS = {
|
13
|
+
target_action: :do_annotations,
|
14
|
+
exit: false
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
ANNOTATION_POSITIONS = %w[before top after bottom].freeze
|
18
|
+
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
|
19
|
+
EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
|
20
|
+
FORMAT_TYPES = %w[bare rdoc yard markdown].freeze
|
21
|
+
|
22
|
+
def initialize(args, env)
|
23
|
+
@args = args
|
24
|
+
@options = DEFAULT_OPTIONS.dup
|
25
|
+
@env = env
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse
|
29
|
+
# To split up because right now this method parses and commits
|
30
|
+
parser.parse!(args)
|
31
|
+
|
32
|
+
commit
|
33
|
+
|
34
|
+
options
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def parser
|
40
|
+
OptionParser.new do |option_parser|
|
41
|
+
add_options_to_parser(option_parser)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def commit
|
46
|
+
env.each_pair do |key, value|
|
47
|
+
ENV[key] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
|
52
|
+
has_set_position = {}
|
53
|
+
|
54
|
+
option_parser.banner = 'Usage: annotate [options] [model_file]*'
|
55
|
+
|
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|
|
59
|
+
ENV['additional_file_patterns'] = additional_file_patterns
|
60
|
+
end
|
61
|
+
|
62
|
+
option_parser.on('-d',
|
63
|
+
'--delete',
|
64
|
+
'Remove annotations from all model files or the routes.rb file') do
|
65
|
+
@options[:target_action] = :remove_annotations
|
66
|
+
end
|
67
|
+
|
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
|
73
|
+
|
74
|
+
FILE_TYPE_POSITIONS.each do |key|
|
75
|
+
env[key] = position unless has_set_position[key]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
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
|
84
|
+
has_set_position['position_in_class'] = true
|
85
|
+
end
|
86
|
+
|
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
|
92
|
+
has_set_position['position_in_factory'] = true
|
93
|
+
end
|
94
|
+
|
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
|
100
|
+
has_set_position['position_in_fixture'] = true
|
101
|
+
end
|
102
|
+
|
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
|
108
|
+
has_set_position['position_in_test'] = true
|
109
|
+
end
|
110
|
+
|
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
|
116
|
+
has_set_position['position_in_routes'] = true
|
117
|
+
end
|
118
|
+
|
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
|
124
|
+
has_set_position['position_in_serializer'] = true
|
125
|
+
end
|
126
|
+
|
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
|
132
|
+
end
|
133
|
+
|
134
|
+
option_parser.on('--wo',
|
135
|
+
'--wrapper-open STR',
|
136
|
+
'Annotation wrapper opening.') do |wrapper_open|
|
137
|
+
env['wrapper_open'] = wrapper_open
|
138
|
+
end
|
139
|
+
|
140
|
+
option_parser.on('--wc',
|
141
|
+
'--wrapper-close STR',
|
142
|
+
'Annotation wrapper closing') do |wrapper_close|
|
143
|
+
env['wrapper_close'] = wrapper_close
|
144
|
+
end
|
145
|
+
|
146
|
+
option_parser.on('-r',
|
147
|
+
'--routes',
|
148
|
+
"Annotate routes.rb with the output of 'rake routes'") do
|
149
|
+
env['routes'] = 'true'
|
150
|
+
end
|
151
|
+
|
152
|
+
option_parser.on('--models',
|
153
|
+
"Annotate ActiveRecord models") do
|
154
|
+
env['models'] = 'true'
|
155
|
+
end
|
156
|
+
|
157
|
+
option_parser.on('-a',
|
158
|
+
'--active-admin',
|
159
|
+
'Annotate active_admin models') do
|
160
|
+
env['active_admin'] = 'true'
|
161
|
+
end
|
162
|
+
|
163
|
+
option_parser.on('-v',
|
164
|
+
'--version',
|
165
|
+
'Show the current version of this gem') do
|
166
|
+
puts "annotate v#{Annotate.version}"
|
167
|
+
@options[:exit] = true
|
168
|
+
end
|
169
|
+
|
170
|
+
option_parser.on('-m',
|
171
|
+
'--show-migration',
|
172
|
+
'Include the migration version number in the annotation') do
|
173
|
+
env['include_version'] = 'yes'
|
174
|
+
end
|
175
|
+
|
176
|
+
option_parser.on('-k',
|
177
|
+
'--show-foreign-keys',
|
178
|
+
"List the table's foreign key constraints in the annotation") do
|
179
|
+
env['show_foreign_keys'] = 'yes'
|
180
|
+
end
|
181
|
+
|
182
|
+
option_parser.on('--ck',
|
183
|
+
'--complete-foreign-keys',
|
184
|
+
'Complete foreign key names in the annotation') do
|
185
|
+
env['show_foreign_keys'] = 'yes'
|
186
|
+
env['show_complete_foreign_keys'] = 'yes'
|
187
|
+
end
|
188
|
+
|
189
|
+
option_parser.on('-i',
|
190
|
+
'--show-indexes',
|
191
|
+
"List the table's database indexes in the annotation") do
|
192
|
+
env['show_indexes'] = 'yes'
|
193
|
+
end
|
194
|
+
|
195
|
+
option_parser.on('-s',
|
196
|
+
'--simple-indexes',
|
197
|
+
"Concat the column's related indexes in the annotation") do
|
198
|
+
env['simple_indexes'] = 'yes'
|
199
|
+
end
|
200
|
+
|
201
|
+
option_parser.on('--model-dir dir',
|
202
|
+
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
|
203
|
+
env['model_dir'] = dir
|
204
|
+
end
|
205
|
+
|
206
|
+
option_parser.on('--root-dir dir',
|
207
|
+
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
|
208
|
+
env['root_dir'] = dir
|
209
|
+
end
|
210
|
+
|
211
|
+
option_parser.on('--ignore-model-subdirects',
|
212
|
+
"Ignore subdirectories of the models directory") do
|
213
|
+
env['ignore_model_sub_dir'] = 'yes'
|
214
|
+
end
|
215
|
+
|
216
|
+
option_parser.on('--sort',
|
217
|
+
"Sort columns alphabetically, rather than in creation order") do
|
218
|
+
env['sort'] = 'yes'
|
219
|
+
end
|
220
|
+
|
221
|
+
option_parser.on('--classified-sort',
|
222
|
+
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do
|
223
|
+
env['classified_sort'] = 'yes'
|
224
|
+
end
|
225
|
+
|
226
|
+
option_parser.on('-R',
|
227
|
+
'--require path',
|
228
|
+
"Additional file to require before loading models, may be used multiple times") do |path|
|
229
|
+
env['require'] = if env['require'].present?
|
230
|
+
"#{env['require']},#{path}"
|
231
|
+
else
|
232
|
+
path
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
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|
|
240
|
+
exclusions ||= EXCLUSION_LIST
|
241
|
+
exclusions.each { |exclusion| env["exclude_#{exclusion}"] = 'yes' }
|
242
|
+
end
|
243
|
+
|
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'
|
249
|
+
end
|
250
|
+
|
251
|
+
option_parser.on('--force',
|
252
|
+
'Force new annotations even if there are no changes.') do
|
253
|
+
env['force'] = 'yes'
|
254
|
+
end
|
255
|
+
|
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
|
258
|
+
env['frozen'] = 'yes'
|
259
|
+
end
|
260
|
+
|
261
|
+
option_parser.on('--timestamp',
|
262
|
+
'Include timestamp in (routes) annotation') do
|
263
|
+
env['timestamp'] = 'true'
|
264
|
+
end
|
265
|
+
|
266
|
+
option_parser.on('--trace',
|
267
|
+
'If unable to annotate a file, print the full stack trace, not just the exception message.') do
|
268
|
+
env['trace'] = 'yes'
|
269
|
+
end
|
270
|
+
|
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|
|
274
|
+
env['ignore_columns'] = regex
|
275
|
+
end
|
276
|
+
|
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|
|
279
|
+
env['ignore_routes'] = regex
|
280
|
+
end
|
281
|
+
|
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|
|
284
|
+
env['hide_limit_column_types'] = values.to_s
|
285
|
+
end
|
286
|
+
|
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|
|
289
|
+
env['hide_default_column_types'] = values.to_s
|
290
|
+
end
|
291
|
+
|
292
|
+
option_parser.on('--ignore-unknown-models',
|
293
|
+
"don't display warnings for bad model files") do
|
294
|
+
env['ignore_unknown_models'] = 'true'
|
295
|
+
end
|
296
|
+
|
297
|
+
option_parser.on('--with-comment',
|
298
|
+
"include database comments in model annotations") do
|
299
|
+
env['with_comment'] = 'true'
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
data/lib/annotate/version.rb
CHANGED
data/lib/annotate.rb
CHANGED
@@ -1,103 +1,92 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
require 'annotate/version'
|
3
3
|
require 'annotate/annotate_models'
|
4
4
|
require 'annotate/annotate_routes'
|
5
|
+
require 'annotate/constants'
|
6
|
+
require 'annotate/helpers'
|
5
7
|
|
6
8
|
begin
|
7
9
|
# ActiveSupport 3.x...
|
8
10
|
require 'active_support/hash_with_indifferent_access'
|
9
|
-
|
11
|
+
require 'active_support/core_ext/object/blank'
|
12
|
+
rescue StandardError
|
10
13
|
# ActiveSupport 2.x...
|
11
14
|
require 'active_support/core_ext/hash/indifferent_access'
|
15
|
+
require 'active_support/core_ext/blank'
|
12
16
|
end
|
13
17
|
|
14
18
|
module Annotate
|
15
|
-
##
|
16
|
-
# The set of available options to customize the behavior of Annotate.
|
17
|
-
#
|
18
|
-
POSITION_OPTIONS=[
|
19
|
-
:position_in_routes, :position_in_class, :position_in_test,
|
20
|
-
:position_in_fixture, :position_in_factory, :position,
|
21
|
-
]
|
22
|
-
FLAG_OPTIONS=[
|
23
|
-
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
|
24
|
-
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
|
25
|
-
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
|
26
|
-
]
|
27
|
-
OTHER_OPTIONS=[
|
28
|
-
:model_dir, :ignore_columns
|
29
|
-
]
|
30
|
-
PATH_OPTIONS=[
|
31
|
-
:require,
|
32
|
-
]
|
33
|
-
|
34
|
-
|
35
19
|
##
|
36
20
|
# Set default values that can be overridden via environment variables.
|
37
21
|
#
|
38
22
|
def self.set_defaults(options = {})
|
39
|
-
return if
|
23
|
+
return if @has_set_defaults
|
40
24
|
@has_set_defaults = true
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
25
|
+
|
26
|
+
options = ActiveSupport::HashWithIndifferentAccess.new(options)
|
27
|
+
|
28
|
+
Constants::ALL_ANNOTATE_OPTIONS.flatten.each do |key|
|
29
|
+
if options.key?(key)
|
30
|
+
default_value = if options[key].is_a?(Array)
|
31
|
+
options[key].join(',')
|
32
|
+
else
|
33
|
+
options[key]
|
34
|
+
end
|
49
35
|
end
|
50
|
-
|
51
|
-
ENV[key.to_s]
|
36
|
+
|
37
|
+
default_value = ENV[key.to_s] unless ENV[key.to_s].blank?
|
38
|
+
ENV[key.to_s] = default_value.nil? ? nil : default_value.to_s
|
52
39
|
end
|
53
40
|
end
|
54
41
|
|
55
|
-
|
42
|
+
##
|
43
|
+
# TODO: what is the difference between this and set_defaults?
|
44
|
+
#
|
56
45
|
def self.setup_options(options = {})
|
57
|
-
POSITION_OPTIONS.each do |key|
|
58
|
-
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')
|
59
48
|
end
|
60
|
-
FLAG_OPTIONS.each do |key|
|
61
|
-
options[key] = true?(ENV[key.to_s])
|
49
|
+
Constants::FLAG_OPTIONS.each do |key|
|
50
|
+
options[key] = Annotate::Helpers.true?(ENV[key.to_s])
|
62
51
|
end
|
63
|
-
OTHER_OPTIONS.each do |key|
|
64
|
-
options[key] =
|
52
|
+
Constants::OTHER_OPTIONS.each do |key|
|
53
|
+
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s] : nil
|
65
54
|
end
|
66
|
-
PATH_OPTIONS.each do |key|
|
67
|
-
options[key] =
|
55
|
+
Constants::PATH_OPTIONS.each do |key|
|
56
|
+
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : []
|
68
57
|
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
options[:additional_file_patterns] ||= []
|
60
|
+
options[:additional_file_patterns] = options[:additional_file_patterns].split(',') if options[:additional_file_patterns].is_a?(String)
|
61
|
+
options[:model_dir] = ['app/models'] if options[:model_dir].empty?
|
73
62
|
|
74
|
-
|
75
|
-
|
63
|
+
options[:wrapper_open] ||= options[:wrapper]
|
64
|
+
options[:wrapper_close] ||= options[:wrapper]
|
76
65
|
|
77
|
-
|
78
|
-
ENV
|
79
|
-
|
66
|
+
# These were added in 2.7.0 but so this is to revert to old behavior by default
|
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'))
|
80
70
|
|
81
|
-
|
82
|
-
|
71
|
+
options
|
72
|
+
end
|
83
73
|
|
84
74
|
def self.load_tasks
|
85
|
-
return if
|
86
|
-
self.loaded_tasks = true
|
75
|
+
return if @tasks_loaded
|
87
76
|
|
88
|
-
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each
|
89
|
-
|
77
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each do |rake|
|
78
|
+
load rake
|
79
|
+
end
|
90
80
|
|
91
|
-
|
92
|
-
options[:require].each { |path| require path } if options[:require].count > 0
|
81
|
+
@tasks_loaded = true
|
93
82
|
end
|
94
83
|
|
95
84
|
def self.eager_load(options)
|
96
|
-
|
97
|
-
require
|
85
|
+
load_requires(options)
|
86
|
+
require 'annotate/active_record_patch'
|
98
87
|
|
99
|
-
if
|
100
|
-
if
|
88
|
+
if defined?(Rails::Application)
|
89
|
+
if Rails.version.split('.').first.to_i < 3
|
101
90
|
Rails.configuration.eager_load_paths.each do |load_path|
|
102
91
|
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
|
103
92
|
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
@@ -109,8 +98,10 @@ module Annotate
|
|
109
98
|
klass.eager_load!
|
110
99
|
end
|
111
100
|
else
|
112
|
-
|
113
|
-
|
101
|
+
options[:model_dir].each do |dir|
|
102
|
+
FileList["#{dir}/**/*.rb"].each do |fname|
|
103
|
+
require File.expand_path(fname)
|
104
|
+
end
|
114
105
|
end
|
115
106
|
end
|
116
107
|
end
|
@@ -118,33 +109,37 @@ module Annotate
|
|
118
109
|
def self.bootstrap_rake
|
119
110
|
begin
|
120
111
|
require 'rake/dsl_definition'
|
121
|
-
rescue
|
112
|
+
rescue StandardError => e
|
122
113
|
# We might just be on an old version of Rake...
|
114
|
+
$stderr.puts e.message
|
115
|
+
exit e.status_code
|
123
116
|
end
|
124
117
|
require 'rake'
|
125
118
|
|
126
|
-
if File.
|
127
|
-
|
119
|
+
load './Rakefile' if File.exist?('./Rakefile')
|
120
|
+
begin
|
121
|
+
Rake::Task[:environment].invoke
|
122
|
+
rescue
|
123
|
+
nil
|
128
124
|
end
|
129
|
-
|
130
|
-
if(!defined?(Rails))
|
125
|
+
unless defined?(Rails)
|
131
126
|
# Not in a Rails project, so time to load up the parts of
|
132
127
|
# ActiveSupport we need.
|
133
128
|
require 'active_support'
|
134
129
|
require 'active_support/core_ext/class/subclasses'
|
135
130
|
require 'active_support/core_ext/string/inflections'
|
136
131
|
end
|
137
|
-
|
132
|
+
|
133
|
+
load_tasks
|
138
134
|
Rake::Task[:set_annotation_options].invoke
|
139
135
|
end
|
140
136
|
|
141
|
-
|
142
|
-
|
143
|
-
end
|
137
|
+
class << self
|
138
|
+
private
|
144
139
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
140
|
+
def load_requires(options)
|
141
|
+
options[:require].count > 0 &&
|
142
|
+
options[:require].each { |path| require path }
|
143
|
+
end
|
149
144
|
end
|
150
145
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
require 'annotate'
|
2
|
+
|
1
3
|
module Annotate
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
desc
|
5
|
-
source_root File.expand_path('
|
6
|
+
desc 'Copy annotate_models rakefiles for automatic annotation'
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
6
8
|
|
7
9
|
# copy rake tasks
|
8
10
|
def copy_tasks
|
9
|
-
template
|
11
|
+
template 'auto_annotate_models.rake', 'lib/tasks/auto_annotate_models.rake'
|
10
12
|
end
|
11
|
-
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -1,33 +1,58 @@
|
|
1
1
|
# NOTE: only doing this in development as some production environments (Heroku)
|
2
2
|
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
|
3
3
|
# NOTE: to have a dev-mode tool do its thing in production.
|
4
|
-
if
|
4
|
+
if Rails.env.development?
|
5
|
+
require 'annotate'
|
5
6
|
task :set_annotation_options do
|
6
7
|
# You can override any of these by setting an environment variable of the
|
7
8
|
# same name.
|
8
|
-
Annotate.set_defaults(
|
9
|
-
'
|
10
|
-
'
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
|
9
|
+
Annotate.set_defaults(
|
10
|
+
'active_admin' => 'false',
|
11
|
+
'additional_file_patterns' => [],
|
12
|
+
'routes' => 'false',
|
13
|
+
'models' => 'true',
|
14
|
+
'position_in_routes' => 'before',
|
15
|
+
'position_in_class' => 'before',
|
16
|
+
'position_in_test' => 'before',
|
17
|
+
'position_in_fixture' => 'before',
|
18
|
+
'position_in_factory' => 'before',
|
19
|
+
'position_in_serializer' => 'before',
|
20
|
+
'show_foreign_keys' => 'true',
|
21
|
+
'show_complete_foreign_keys' => 'false',
|
22
|
+
'show_indexes' => 'true',
|
23
|
+
'simple_indexes' => 'false',
|
24
|
+
'model_dir' => 'app/models',
|
25
|
+
'root_dir' => '',
|
26
|
+
'include_version' => 'false',
|
27
|
+
'require' => '',
|
28
|
+
'exclude_tests' => 'false',
|
29
|
+
'exclude_fixtures' => 'false',
|
30
|
+
'exclude_factories' => 'false',
|
31
|
+
'exclude_serializers' => 'false',
|
32
|
+
'exclude_scaffolds' => 'true',
|
33
|
+
'exclude_controllers' => 'true',
|
34
|
+
'exclude_helpers' => 'true',
|
35
|
+
'exclude_sti_subclasses' => 'false',
|
36
|
+
'ignore_model_sub_dir' => 'false',
|
37
|
+
'ignore_columns' => nil,
|
38
|
+
'ignore_routes' => nil,
|
39
|
+
'ignore_unknown_models' => 'false',
|
40
|
+
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
|
41
|
+
'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>',
|
42
|
+
'skip_on_db_migrate' => 'false',
|
43
|
+
'format_bare' => 'true',
|
44
|
+
'format_rdoc' => 'false',
|
45
|
+
'format_yard' => 'false',
|
46
|
+
'format_markdown' => 'false',
|
47
|
+
'sort' => 'false',
|
48
|
+
'force' => 'false',
|
49
|
+
'frozen' => 'false',
|
50
|
+
'classified_sort' => 'true',
|
51
|
+
'trace' => 'false',
|
52
|
+
'wrapper_open' => nil,
|
53
|
+
'wrapper_close' => nil,
|
54
|
+
'with_comment' => 'true'
|
55
|
+
)
|
31
56
|
end
|
32
57
|
|
33
58
|
Annotate.load_tasks
|