Commit 49e5fce3 by Alex Chaffee

Merge remote branch 'jacqui/master'

* jacqui/master: Pass options to annotate_one_file for specs/tests/exemplars as well Refactoring & making work with Neal's 'exclude' option too.
parents 0f978c57 597c862d
== Fork of AnnotateModels
I forked AnnotateModels to fix what I'm guessing is a bug - options (including position) were not being passed when annotating spec, test, or exemplar files. This resulted in my models having annotations at the bottom of my models but at the top of my specs, which was frustrating.
This version of AnnotateModels will pass all options to the method annotate_one_file when annotating models and specs (or tests, or exemplars, whatever you use). Otherwise this version is exactly the same as the original!
== AnnotateModels == AnnotateModels
Add a comment summarizing the current schema to the bottom of each Add a comment summarizing the current schema to the bottom of each
......
...@@ -106,6 +106,7 @@ module AnnotateModels ...@@ -106,6 +106,7 @@ module AnnotateModels
old_header = old_content.match(header).to_s old_header = old_content.match(header).to_s
new_header = info_block.match(header).to_s new_header = info_block.match(header).to_s
old_header = ""
if old_header == new_header if old_header == new_header
false false
else else
...@@ -137,37 +138,45 @@ module AnnotateModels ...@@ -137,37 +138,45 @@ module AnnotateModels
# of the model and fixture source files. # of the model and fixture source files.
# Returns true or false depending on whether the source # Returns true or false depending on whether the source
# files were modified. # files were modified.
def annotate(klass, file, header,options={}) def annotate(klass, file, header,options={})
info = get_schema_info(klass, header, options) info = get_schema_info(klass, header, options)
annotated = false annotated = false
model_name = klass.name.underscore model_name = klass.name.underscore
model_file_name = File.join(model_dir, file) model_file_name = File.join(model_dir, file)
if annotate_one_file(model_file_name, info, options.merge(
:position=>(options[:position_in_class] || options[:position])))
annotated = true
end
annotate_tests(info, model_name) unless ENV['exclude_tests'] if annotate_one_file(model_file_name, info, options_with_position(:position_in_class))
annotate_fixtures(info, klass, options) unless ENV['exclude_fixtures'] annotated = true
annotated
end end
def annotate_tests(info, model_name) unless ENV['exclude_tests']
[ [
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 ].each do |file|
].each { |file| annotate_one_file(file, info) } annotate_one_file(file, info, options_with_position(:position_in_fixture))
end
end end
def annotate_fixtures(info, klass, options) unless ENV['exclude_fixtures']
file = File.join(EXEMPLARS_DIR, "#{model_name}_exemplar.rb") # Object Daddy
annotate_one_file(file, info, options_with_position(:position_in_fixture))
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) if File.exist?(fixture_file_name)
annotate_one_file(fixture_file_name, info, options_with_position(:position_in_fixture))
end
end end
end end
annotated
end
# position = :position_in_fixture or :position_in_class
def options_with_position(position_in)
options.merge(:position=>(options[position_in] || options[:position]))
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
# command line arguments, they're assumed to be either # command line arguments, they're assumed to be either
# the underscore or CamelCase versions of model names. # the underscore or CamelCase versions of model names.
...@@ -235,7 +244,7 @@ module AnnotateModels ...@@ -235,7 +244,7 @@ module AnnotateModels
begin begin
klass = get_model_class(file) klass = get_model_class(file)
if klass < ActiveRecord::Base && !klass.abstract_class? if klass < ActiveRecord::Base && !klass.abstract_class?
if annotate(klass, file, header,options) if annotate(klass, file, header, options)
annotated << klass annotated << klass
end end
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