Skip to content

Commit 3b3b434

Browse files
committed
Adding explicit CLI options for each position variable.
1 parent 120a0c4 commit 3b3b434

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

CHANGELOG.rdoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
wasn't even looking for FactoryGirl factories under the new naming
55
convention.
66
* Added support for new FactoryGirl naming convention.
7+
* Expose all `position_*` variables as CLI params.
8+
* Make `ENV ['position']` work as a default for all the `ENV ['position_*']`
9+
variables.
710
* Fixed that schema kept prepending additional newlines
811
* Updates to make annotate smarter about when to touch a model
912
* Recognize column+type, and don't change a file unless the column+type

README.rdoc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,16 @@ anywhere in the file:
102102
== OPTIONS
103103

104104
Usage: annotate [options] [model_file]*
105-
-d, --delete Remove annotations from all model files
106-
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model file
105+
-d, --delete Remove annotations from all model files or the routes.rb file
106+
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)
107+
--pc, --position-in-class [before|after]
108+
Place the annotations at the top (before) or the bottom (after) of the model file
109+
--pf, --position-in-factory [before|after]
110+
Place the annotations at the top (before) or the bottom (after) of any factory files
111+
--px, --position-in-fixture [before|after]
112+
Place the annotations at the top (before) or the bottom (after) of any fixture files
113+
--pt, --position-in-test [before|after]
114+
Place the annotations at the top (before) or the bottom (after) of any test files
107115
-r, --routes Annotate routes.rb with the output of 'rake routes'
108116
-v, --version Show the current version of this gem
109117
-m, --show-migration Include the migration version number in the annotation
@@ -112,14 +120,14 @@ anywhere in the file:
112120
--model-dir dir Annotate model files stored in dir rather than app/models
113121
--ignore-model-subdirects Ignore subdirectories of the models directory
114122
--sort Sort columns alphabetically, rather than in creation order
115-
-R, --require path Additional files to require before loading models
116-
-e, --exclude [tests,fixtures] Do not annotate fixtures, test files, or both
123+
-R, --require path Additional file to require before loading models, may be used multiple times
124+
-e [tests,fixtures,factories], Do not annotate fixtures, test files, and/or factories
125+
--exclude
117126
-f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown
118127
--format
119128
--force Force new annotations even if there are no changes.
120129
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
121130

122-
123131
== SORTING
124132

125133
By default, columns will be sorted in database order (i.e. the order in which migrations were run).

bin/annotate

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require 'annotate'
2020

2121
task = :annotate_models
2222

23+
has_set_position = {}
2324
OptionParser.new do |opts|
2425
opts.banner = "Usage: annotate [options] [model_file]*"
2526

@@ -32,6 +33,35 @@ OptionParser.new do |opts|
3233
opts.on('-p', '--position [before|after]', ['before', 'after'],
3334
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
3435
ENV['position'] = p
36+
[
37+
'position_in_class','position_in_factory','position_in_fixture','position_in_test'
38+
].each do |key|
39+
ENV[key] = p unless(has_set_position[key])
40+
end
41+
end
42+
43+
opts.on('--pc', '--position-in-class [before|after]', ['before', 'after'],
44+
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
45+
ENV['position_in_class'] = p
46+
has_set_position['position_in_class'] = true
47+
end
48+
49+
opts.on('--pf', '--position-in-factory [before|after]', ['before', 'after'],
50+
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |p|
51+
ENV['position_in_factory'] = p
52+
has_set_position['position_in_factory'] = true
53+
end
54+
55+
opts.on('--px', '--position-in-fixture [before|after]', ['before', 'after'],
56+
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |p|
57+
ENV['position_in_fixture'] = p
58+
has_set_position['position_in_fixture'] = true
59+
end
60+
61+
opts.on('--pt', '--position-in-test [before|after]', ['before', 'after'],
62+
"Place the annotations at the top (before) or the bottom (after) of any test files") do |p|
63+
ENV['position_in_test'] = p
64+
has_set_position['position_in_test'] = true
3565
end
3666

3767
opts.on('-r', '--routes',

lib/tasks/annotate_models.rake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ task :annotate_models => :environment do
1616
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
1717
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
1818
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
19+
options[:position_in_test] = ENV['position_in_test'] || ENV['position'] || 'before'
1920
options[:show_indexes] = ENV['show_indexes'] =~ true_re
2021
options[:simple_indexes] = ENV['simple_indexes'] =~ true_re
2122
options[:model_dir] = ENV['model_dir']
2223
options[:include_version] = ENV['include_version'] =~ true_re
2324
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
2425
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
26+
options[:exclude_factories] = ENV['exclude_factories'] =~ true_re
2527
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
2628
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
29+
options[:format_bare] = ENV['format_bare'] =~ true_re
2730
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
2831
options[:format_markdown] = ENV['format_markdown'] =~ true_re
2932
options[:sort] = ENV['sort'] =~ true_re
@@ -36,7 +39,11 @@ desc "Remove schema information from model and fixture files"
3639
task :remove_annotation => :environment do
3740
require "#{annotate_lib}/annotate/annotate_models"
3841
require "#{annotate_lib}/annotate/active_record_patch"
42+
43+
true_re = /(true|t|yes|y|1)$/i
44+
3945
options={ :is_rake => true }
4046
options[:model_dir] = ENV['model_dir']
47+
options[:trace] = ENV['trace'] =~ true_re
4148
AnnotateModels.remove_annotations(options)
4249
end

0 commit comments

Comments
 (0)