Commit 3fdb185d by miyucy

reindent (use ruby-mode.el)

parent 7d8f70f1
...@@ -8,48 +8,48 @@ task = :annotate_models ...@@ -8,48 +8,48 @@ task = :annotate_models
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: annotate [options] [model_file]*" opts.banner = "Usage: annotate [options] [model_file]*"
opts.on('-d', '--delete', opts.on('-d', '--delete',
"Remove annotations from all model files") do "Remove annotations from all model files") do
task = :remove_annotation task = :remove_annotation
end end
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 file") do |p| "Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
ENV['position'] = p ENV['position'] = p
end end
opts.on('-r', '--routes', opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do "Annotate routes.rb with the output of 'rake routes'") do
task = :annotate_routes task = :annotate_routes
end end
opts.on('-v', '--version', opts.on('-v', '--version',
"Show the current version of this gem") do "Show the current version of this gem") do
puts "annotate v#{Annotate.version}"; exit puts "annotate v#{Annotate.version}"; exit
end end
opts.on('-m', '--show-migration', opts.on('-m', '--show-migration',
"Include the migration version number in the annotation") do "Include the migration version number in the annotation") do
ENV['include_version'] = "yes" ENV['include_version'] = "yes"
end end
opts.on('-i', '--show-indexes', opts.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do "List the table's database indexes in the annotation") do
ENV['show_indexes'] = "yes" ENV['show_indexes'] = "yes"
end end
opts.on('-s', '--simple-indexes', opts.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do "Concat the column's related indexes in the annotation") do
ENV['simple_indexes'] = "yes" ENV['simple_indexes'] = "yes"
end end
opts.on('--model-dir dir', opts.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models") do |dir| "Annotate model files stored in dir rather than app/models") do |dir|
ENV['model_dir'] = dir ENV['model_dir'] = dir
end end
opts.on('-R', '--require path', opts.on('-R', '--require path',
"Additional files to require before loading models") do |path| "Additional files to require before loading models") do |path|
if ENV['require'] if ENV['require']
ENV['require'] = ENV['require'] + ",#{path}" ENV['require'] = ENV['require'] + ",#{path}"
else else
...@@ -57,7 +57,7 @@ OptionParser.new do |opts| ...@@ -57,7 +57,7 @@ OptionParser.new do |opts|
end end
end end
opts.on('-e', '--exclude [tests,fixtures,factories]', Array, "Do not annotate fixtures, test files, and/or factories") do |exclusions| opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" } exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end end
......
...@@ -34,14 +34,14 @@ module AnnotateModels ...@@ -34,14 +34,14 @@ module AnnotateModels
# Simple quoting for the default column value # Simple quoting for the default column value
def quote(value) def quote(value)
case value case value
when NilClass then "NULL" when NilClass then "NULL"
when TrueClass then "TRUE" when TrueClass then "TRUE"
when FalseClass then "FALSE" when FalseClass then "FALSE"
when Float, Fixnum, Bignum then value.to_s when Float, Fixnum, Bignum then value.to_s
# BigDecimals need to be output in a non-normalized form and quoted. # BigDecimals need to be output in a non-normalized form and quoted.
when BigDecimal then value.to_s('F') when BigDecimal then value.to_s('F')
else else
value.inspect value.inspect
end end
end end
...@@ -140,7 +140,7 @@ module AnnotateModels ...@@ -140,7 +140,7 @@ module AnnotateModels
old_content.sub!(/^\n?# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '') old_content.sub!(/^\n?# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n/, '')
# Write it back # Write it back
new_content = options[:position].to_s == 'after' ? (old_content + "\n" + info_block) : (info_block + old_content) new_content = options[:position].to_s == 'after' ? (old_content + "\n" + info_block) : (info_block + old_content)
File.open(file_name, "wb") { |f| f.puts new_content } File.open(file_name, "wb") { |f| f.puts new_content }
true true
...@@ -176,8 +176,8 @@ module AnnotateModels ...@@ -176,8 +176,8 @@ module AnnotateModels
unless ENV['exclude_tests'] 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
].each do |file| ].each do |file|
# todo: add an option "position_in_test" -- or maybe just ask if anyone ever wants different positions for model vs. test vs. fixture # todo: add an option "position_in_test" -- or maybe just ask if anyone ever wants different positions for model vs. test vs. fixture
annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) annotate_one_file(file, info, options_with_position(options, :position_in_fixture))
...@@ -186,13 +186,13 @@ module AnnotateModels ...@@ -186,13 +186,13 @@ module AnnotateModels
unless ENV['exclude_fixtures'] unless ENV['exclude_fixtures']
[ [
File.join(EXEMPLARS_TEST_DIR, "#{model_name}_exemplar.rb"), # Object Daddy File.join(EXEMPLARS_TEST_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
].each do |file| ].each do |file|
annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) annotate_one_file(file, info, options_with_position(options, :position_in_fixture))
end end
FIXTURE_DIRS.each do |dir| FIXTURE_DIRS.each do |dir|
...@@ -205,8 +205,8 @@ module AnnotateModels ...@@ -205,8 +205,8 @@ module AnnotateModels
unless ENV['exclude_factories'] unless ENV['exclude_factories']
[ [
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # spec/factories File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # spec/factories
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # test/factories File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # test/factories
].each do |file| ].each do |file|
annotate_one_file(file, info, options_with_position(options, :position_in_factory)) annotate_one_file(file, info, options_with_position(options, :position_in_factory))
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