Commit 637499db by Alex Chaffee

Revert "Changed to sort be default with an option to not sort."

This reverts commit 8d3c00c7. Sorry, but database order should be the default unless a user really wants it alphabetized. (We should also allow a .annotate file so users can set their own preferred options more easily.) Conflicts: .gitignore bin/annotate lib/annotate/annotate_models.rb lib/tasks/annotate_models.rake
parent 60381f84
...@@ -61,9 +61,9 @@ OptionParser.new do |opts| ...@@ -61,9 +61,9 @@ OptionParser.new do |opts|
ENV['ignore_model_sub_dir'] = "yes" ENV['ignore_model_sub_dir'] = "yes"
end end
opts.on('-n', '--no-sort', opts.on('--sort',
"Sort columns in creation order rather than alphabetically") do |dir| "Sort columns alphabetically, rather than in creation order") do |dir|
ENV['no_sort'] = "yes" ENV['sort'] = "yes"
end end
opts.on('-R', '--require path', opts.on('-R', '--require path',
...@@ -73,7 +73,7 @@ OptionParser.new do |opts| ...@@ -73,7 +73,7 @@ OptionParser.new do |opts|
else else
ENV['require'] = path ENV['require'] = path
end end
end end\
opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") 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" }
......
...@@ -39,7 +39,7 @@ module AnnotateModels ...@@ -39,7 +39,7 @@ module AnnotateModels
def model_dir def model_dir
@model_dir || "app/models" @model_dir || "app/models"
end end
def model_dir=(dir) def model_dir=(dir)
@model_dir = dir @model_dir = dir
end end
...@@ -77,7 +77,7 @@ module AnnotateModels ...@@ -77,7 +77,7 @@ module AnnotateModels
end end
cols = klass.columns cols = klass.columns
cols = cols.sort_by(&:name) unless(options[:no_sort]) cols = cols.sort_by(&:name) if(options[:sort])
cols.each do |col| cols.each do |col|
attrs = [] attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil? attrs << "default(#{quote(col.default)})" unless col.default.nil?
...@@ -92,7 +92,7 @@ module AnnotateModels ...@@ -92,7 +92,7 @@ module AnnotateModels
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type) col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
end end
end end
# Check out if we got a geometric column # Check out if we got a geometric column
# and print the type and SRID # and print the type and SRID
if col.respond_to?(:geometry_type) if col.respond_to?(:geometry_type)
...@@ -207,13 +207,11 @@ module AnnotateModels ...@@ -207,13 +207,11 @@ module AnnotateModels
end end
end end
end end
def remove_annotation_of_file(file_name) def remove_annotation_of_file(file_name)
if File.exist?(file_name) if File.exist?(file_name)
content = File.read(file_name) content = File.read(file_name)
content.sub!(PATTERN, '') content.sub!(PATTERN, '')
File.open(file_name, "wb") { |f| f.puts content } File.open(file_name, "wb") { |f| f.puts content }
end end
end end
...@@ -304,7 +302,7 @@ module AnnotateModels ...@@ -304,7 +302,7 @@ module AnnotateModels
end end
models models
end end
# Retrieve the classes belonging to the model names we're asked to process # Retrieve the classes belonging to the model names we're asked to process
# Check for namespaced models in subdirectories as well as models # Check for namespaced models in subdirectories as well as models
# in subdirectories without namespacing. # in subdirectories without namespacing.
...@@ -340,9 +338,9 @@ module AnnotateModels ...@@ -340,9 +338,9 @@ module AnnotateModels
version = ActiveRecord::Migrator.current_version rescue 0 version = ActiveRecord::Migrator.current_version rescue 0
if version > 0 if version > 0
header << "\n# Schema version: #{version}" header << "\n# Schema version: #{version}"
end end
end end
if options[:model_dir] if options[:model_dir]
self.model_dir = options[:model_dir] self.model_dir = options[:model_dir]
end end
...@@ -367,7 +365,7 @@ module AnnotateModels ...@@ -367,7 +365,7 @@ module AnnotateModels
puts "Annotated (#{annotated.length}): #{annotated.join(', ')}" puts "Annotated (#{annotated.length}): #{annotated.join(', ')}"
end end
end end
def remove_annotations(options={}) def remove_annotations(options={})
if options[:model_dir] if options[:model_dir]
puts "removing" puts "removing"
......
...@@ -26,7 +26,7 @@ task :annotate_models => :environment do ...@@ -26,7 +26,7 @@ task :annotate_models => :environment do
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_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[:no_sort] = ENV['no_sort'] =~ true_re options[:sort] = ENV['sort'] =~ true_re
options[:force] = ENV['force'] =~ true_re options[:force] = ENV['force'] =~ true_re
AnnotateModels.do_annotations(options) AnnotateModels.do_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