Commit 3b3b4343 by Jon Frisby

Adding explicit CLI options for each position variable.

parent 120a0c49
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
wasn't even looking for FactoryGirl factories under the new naming wasn't even looking for FactoryGirl factories under the new naming
convention. convention.
* Added support for new FactoryGirl naming convention. * Added support for new FactoryGirl naming convention.
* Expose all `position_*` variables as CLI params.
* Make `ENV ['position']` work as a default for all the `ENV ['position_*']`
variables.
* Fixed that schema kept prepending additional newlines * Fixed that schema kept prepending additional newlines
* Updates to make annotate smarter about when to touch a model * Updates to make annotate smarter about when to touch a model
* Recognize column+type, and don't change a file unless the column+type * Recognize column+type, and don't change a file unless the column+type
......
...@@ -102,8 +102,16 @@ anywhere in the file: ...@@ -102,8 +102,16 @@ anywhere in the file:
== OPTIONS == OPTIONS
Usage: annotate [options] [model_file]* Usage: annotate [options] [model_file]*
-d, --delete Remove annotations from all model files -d, --delete Remove annotations from all model files or the routes.rb file
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model file -p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)
--pc, --position-in-class [before|after]
Place the annotations at the top (before) or the bottom (after) of the model file
--pf, --position-in-factory [before|after]
Place the annotations at the top (before) or the bottom (after) of any factory files
--px, --position-in-fixture [before|after]
Place the annotations at the top (before) or the bottom (after) of any fixture files
--pt, --position-in-test [before|after]
Place the annotations at the top (before) or the bottom (after) of any test files
-r, --routes Annotate routes.rb with the output of 'rake routes' -r, --routes Annotate routes.rb with the output of 'rake routes'
-v, --version Show the current version of this gem -v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation -m, --show-migration Include the migration version number in the annotation
...@@ -112,14 +120,14 @@ anywhere in the file: ...@@ -112,14 +120,14 @@ anywhere in the file:
--model-dir dir Annotate model files stored in dir rather than app/models --model-dir dir Annotate model files stored in dir rather than app/models
--ignore-model-subdirects Ignore subdirectories of the models directory --ignore-model-subdirects Ignore subdirectories of the models directory
--sort Sort columns alphabetically, rather than in creation order --sort Sort columns alphabetically, rather than in creation order
-R, --require path Additional files to require before loading models -R, --require path Additional file to require before loading models, may be used multiple times
-e, --exclude [tests,fixtures] Do not annotate fixtures, test files, or both -e [tests,fixtures,factories], Do not annotate fixtures, test files, and/or factories
--exclude
-f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown -f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown
--format --format
--force Force new annotations even if there are no changes. --force Force new annotations even if there are no changes.
--trace If unable to annotate a file, print the full stack trace, not just the exception message. --trace If unable to annotate a file, print the full stack trace, not just the exception message.
== SORTING == SORTING
By default, columns will be sorted in database order (i.e. the order in which migrations were run). By default, columns will be sorted in database order (i.e. the order in which migrations were run).
......
...@@ -20,6 +20,7 @@ require 'annotate' ...@@ -20,6 +20,7 @@ require 'annotate'
task = :annotate_models task = :annotate_models
has_set_position = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: annotate [options] [model_file]*" opts.banner = "Usage: annotate [options] [model_file]*"
...@@ -32,6 +33,35 @@ OptionParser.new do |opts| ...@@ -32,6 +33,35 @@ OptionParser.new do |opts|
opts.on('-p', '--position [before|after]', ['before', 'after'], opts.on('-p', '--position [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p| "Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
ENV['position'] = p ENV['position'] = p
[
'position_in_class','position_in_factory','position_in_fixture','position_in_test'
].each do |key|
ENV[key] = p unless(has_set_position[key])
end
end
opts.on('--pc', '--position-in-class [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
ENV['position_in_class'] = p
has_set_position['position_in_class'] = true
end
opts.on('--pf', '--position-in-factory [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |p|
ENV['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
opts.on('--px', '--position-in-fixture [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |p|
ENV['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
opts.on('--pt', '--position-in-test [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of any test files") do |p|
ENV['position_in_test'] = p
has_set_position['position_in_test'] = true
end end
opts.on('-r', '--routes', opts.on('-r', '--routes',
......
...@@ -16,14 +16,17 @@ task :annotate_models => :environment do ...@@ -16,14 +16,17 @@ task :annotate_models => :environment do
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before' options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before' options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before' options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
options[:position_in_test] = ENV['position_in_test'] || ENV['position'] || 'before'
options[:show_indexes] = ENV['show_indexes'] =~ true_re options[:show_indexes] = ENV['show_indexes'] =~ true_re
options[:simple_indexes] = ENV['simple_indexes'] =~ true_re options[:simple_indexes] = ENV['simple_indexes'] =~ true_re
options[:model_dir] = ENV['model_dir'] options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version'] =~ true_re options[:include_version] = ENV['include_version'] =~ true_re
options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
options[:exclude_factories] = ENV['exclude_factories'] =~ true_re
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
options[:format_bare] = ENV['format_bare'] =~ true_re
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
options[:format_markdown] = ENV['format_markdown'] =~ true_re options[:format_markdown] = ENV['format_markdown'] =~ true_re
options[:sort] = ENV['sort'] =~ true_re options[:sort] = ENV['sort'] =~ true_re
...@@ -36,7 +39,11 @@ desc "Remove schema information from model and fixture files" ...@@ -36,7 +39,11 @@ desc "Remove schema information from model and fixture files"
task :remove_annotation => :environment do task :remove_annotation => :environment do
require "#{annotate_lib}/annotate/annotate_models" require "#{annotate_lib}/annotate/annotate_models"
require "#{annotate_lib}/annotate/active_record_patch" require "#{annotate_lib}/annotate/active_record_patch"
true_re = /(true|t|yes|y|1)$/i
options={ :is_rake => true } options={ :is_rake => true }
options[:model_dir] = ENV['model_dir'] options[:model_dir] = ENV['model_dir']
options[:trace] = ENV['trace'] =~ true_re
AnnotateModels.remove_annotations(options) AnnotateModels.remove_annotations(options)
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment