Commit d430889d by Neal Clark

adding option to not annotate tests or fixtures

parent 8ecd23ee
...@@ -51,11 +51,19 @@ From github: ...@@ -51,11 +51,19 @@ From github:
== Usage == Usage
To annotate all your models: To annotate all your models, tests, and fixtures:
cd /path/to/app cd /path/to/app
annotate annotate
To annotate your models and tests:
annotate --exclude fixtures
To annotate just your models:
annotate --exclude tests,fixtures
To annotate routes.rb: To annotate routes.rb:
annotate -r annotate -r
...@@ -69,6 +77,7 @@ More options: ...@@ -69,6 +77,7 @@ More options:
-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
-i, --show-indexes List the table's database indexes in the annotation -i, --show-indexes List the table's database indexes in the annotation
-e, --exclude [fixtures,tests] Do not annotate fixtures, test files, or both
--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
== LICENSE: == LICENSE:
......
...@@ -13,6 +13,9 @@ OptionParser.new do |opts| ...@@ -13,6 +13,9 @@ OptionParser.new do |opts|
opts.on('-v', '--version', "Show the current version of this gem") { puts "Annotate v#{Annotate::VERSION}"; exit } opts.on('-v', '--version', "Show the current version of this gem") { puts "Annotate v#{Annotate::VERSION}"; exit }
opts.on('-m', '--show-migration', "Include the migration version number in the annotation") { ENV['include_version'] = "yes" } opts.on('-m', '--show-migration', "Include the migration version number in the annotation") { ENV['include_version'] = "yes" }
opts.on('-i', '--show-indexes', "List the table's database indexes in the annotation") { ENV['show_indexes'] = "yes" } opts.on('-i', '--show-indexes', "List the table's database indexes in the annotation") { ENV['show_indexes'] = "yes" }
opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end
opts.on('--model-dir dir', "Annotate model files stored in dir rather than app/models") {|dir| ENV['model_dir'] = dir } opts.on('--model-dir dir', "Annotate model files stored in dir rather than app/models") {|dir| ENV['model_dir'] = dir }
end.parse! end.parse!
......
...@@ -148,17 +148,24 @@ module AnnotateModels ...@@ -148,17 +148,24 @@ module AnnotateModels
annotated = true annotated = true
end end
annotate_tests(info, model_name) unless ENV['exclude_tests']
annotate_fixtures(info, klass, options) unless ENV['exclude_fixtures']
annotated
end
def annotate_tests(info, model_name)
[ [
File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test File.join(UNIT_TEST_DIR, "#{model_name}_test.rb"), # test
File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec File.join(SPEC_MODEL_DIR, "#{model_name}_spec.rb"), # spec
File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
].each { |file| annotate_one_file(file, info) } ].each { |file| annotate_one_file(file, info) }
end
def annotate_fixtures(info, klass, options)
FIXTURE_DIRS.each do |dir| FIXTURE_DIRS.each do |dir|
fixture_file_name = File.join(dir,klass.table_name + ".yml") fixture_file_name = File.join(dir, klass.table_name + ".yml")
annotate_one_file(fixture_file_name, info, options.merge(:position=>(options[:position_in_fixture] || options[:position]))) if File.exist?(fixture_file_name) annotate_one_file(fixture_file_name, info, options.merge(:position=>(options[:position_in_fixture] || options[:position]))) if File.exist?(fixture_file_name)
end end
annotated
end end
# Return a list of the model files to annotate. If we have # Return a list of the model files to annotate. If we have
...@@ -245,7 +252,7 @@ module AnnotateModels ...@@ -245,7 +252,7 @@ module AnnotateModels
model_file_name = File.join(model_dir, file) model_file_name = File.join(model_dir, file)
remove_annotation_of_file(model_file_name) remove_annotation_of_file(model_file_name)
FIXTURE_DIRS.each do |dir| FIXTURE_DIRS.each do |dir|
fixture_file_name = File.join(dir,klass.table_name + ".yml") fixture_file_name = File.join(dir,klass.table_name + ".yml")
remove_annotation_of_file(fixture_file_name) if File.exist?(fixture_file_name) remove_annotation_of_file(fixture_file_name) if File.exist?(fixture_file_name)
......
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