Skip to content

Commit 8927c88

Browse files
committed
Make option handling more consistent.
1 parent 0f04036 commit 8927c88

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

README.rdoc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,35 @@ Into environment gems from Github checkout:
6464

6565
(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
6666

67-
To annotate all your models, tests, fixtures, etc.:
67+
To annotate all your models, tests, fixtures, and factories:
6868

69-
cd /path/to/app
70-
annotate
69+
cd /path/to/app
70+
annotate
7171

72-
To annotate your models and tests:
72+
To annotate your models, tests, and factories:
7373

74-
annotate --exclude fixtures
74+
annotate --exclude fixtures
7575

7676
To annotate just your models:
7777

78-
annotate --exclude tests,fixtures
78+
annotate --exclude tests,fixtures,factories
7979

8080
To annotate routes.rb:
8181

82-
annotate -r
82+
annotate -r
8383

84-
To remove annotations:
84+
To remove model/test/fixture/factory annotations:
8585

86-
annotate -d
86+
annotate -d
87+
88+
To remove routes.rb annotations:
89+
90+
annotate -r -d
8791

8892
To automatically annotate after running 'rake db:migrate', ensure you've added
8993
annotate_models to your Rails project's Gemfile, and run this:
9094

91-
rails g annotate_models:install
95+
rails g annotate_models:install
9296

9397
This will produce a .rake file that will ensure annotation happens after
9498
migration (but only in development mode), and provide configuration options
@@ -97,7 +101,7 @@ you can use to tailor the output.
97101
If you want to always skip annotations on a particular model, add this string
98102
anywhere in the file:
99103

100-
# -*- SkipSchemaAnnotations
104+
# -*- SkipSchemaAnnotations
101105

102106
== OPTIONS
103107

bin/annotate

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ OptionParser.new do |opts|
3333
end
3434
end
3535

36-
ENV['position'] = 'before' # hack: make sure default position is "before"
3736
opts.on('-p', '--position [before|after]', ['before', 'after'],
3837
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
3938
ENV['position'] = p

lib/tasks/annotate_models.rake

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,27 @@ task :annotate_models => :environment do
1010
require "#{annotate_lib}/annotate/annotate_models"
1111
require "#{annotate_lib}/annotate/active_record_patch"
1212

13-
true_re = /(true|t|yes|y|1)$/i
14-
1513
options={ :is_rake => true }
16-
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
17-
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
18-
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
19-
options[:position_in_test] = ENV['position_in_test'] || ENV['position'] || 'before'
20-
options[:show_indexes] = ENV['show_indexes'] =~ true_re
21-
options[:simple_indexes] = ENV['simple_indexes'] =~ true_re
14+
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
15+
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
16+
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
17+
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
18+
options[:position_in_test] = Annotate.fallback(ENV['position_in_test'], ENV['position'])
19+
options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
20+
options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
2221
options[:model_dir] = ENV['model_dir']
23-
options[:include_version] = ENV['include_version'] =~ true_re
22+
options[:include_version] = Annotate.true?(ENV['include_version'])
2423
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
25-
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
26-
options[:exclude_factories] = ENV['exclude_factories'] =~ true_re
27-
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
28-
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
29-
options[:format_bare] = ENV['format_bare'] =~ true_re
30-
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
31-
options[:format_markdown] = ENV['format_markdown'] =~ true_re
32-
options[:sort] = ENV['sort'] =~ true_re
33-
options[:force] = ENV['force'] =~ true_re
34-
options[:trace] = ENV['trace'] =~ true_re
24+
options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
25+
options[:exclude_factories] = Annotate.true?(ENV['exclude_factories'])
26+
options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
27+
options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
28+
options[:format_bare] = Annotate.true?(ENV['format_bare'])
29+
options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
30+
options[:format_markdown] = Annotate.true?(ENV['format_markdown'])
31+
options[:sort] = Annotate.true?(ENV['sort'])
32+
options[:force] = Annotate.true?(ENV['force'])
33+
options[:trace] = Annotate.true?(ENV['trace'])
3534
AnnotateModels.do_annotations(options)
3635
end
3736

@@ -40,11 +39,9 @@ task :remove_annotation => :environment do
4039
require "#{annotate_lib}/annotate/annotate_models"
4140
require "#{annotate_lib}/annotate/active_record_patch"
4241

43-
true_re = /(true|t|yes|y|1)$/i
44-
4542
options={ :is_rake => true }
4643
options[:model_dir] = ENV['model_dir']
4744
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
48-
options[:trace] = ENV['trace'] =~ true_re
45+
options[:trace] = Annotate.true?(ENV['trace'])
4946
AnnotateModels.remove_annotations(options)
5047
end

lib/tasks/annotate_routes.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ task :annotate_routes => :environment do
44
require "#{annotate_lib}/annotate/annotate_routes"
55

66
options={}
7-
options[:position_in_routes] = ENV['position_in_routes'] || ENV['position'] || 'after'
7+
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
8+
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
89
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
910
AnnotateRoutes.do_annotate(options)
1011
end

0 commit comments

Comments
 (0)