Skip to content

Commit 637499d

Browse files
committed
Revert "Changed to sort be default with an option to not sort."
This reverts commit 8d3c00c. 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
1 parent 60381f8 commit 637499d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

bin/annotate

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ OptionParser.new do |opts|
6161
ENV['ignore_model_sub_dir'] = "yes"
6262
end
6363

64-
opts.on('-n', '--no-sort',
65-
"Sort columns in creation order rather than alphabetically") do |dir|
66-
ENV['no_sort'] = "yes"
64+
opts.on('--sort',
65+
"Sort columns alphabetically, rather than in creation order") do |dir|
66+
ENV['sort'] = "yes"
6767
end
6868

6969
opts.on('-R', '--require path',
@@ -73,7 +73,7 @@ OptionParser.new do |opts|
7373
else
7474
ENV['require'] = path
7575
end
76-
end
76+
end\
7777

7878
opts.on('-e', '--exclude [tests,fixtures]', Array, "Do not annotate fixtures, test files, or both") do |exclusions|
7979
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }

lib/annotate/annotate_models.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class << self
3939
def model_dir
4040
@model_dir || "app/models"
4141
end
42-
42+
4343
def model_dir=(dir)
4444
@model_dir = dir
4545
end
@@ -77,7 +77,7 @@ def get_schema_info(klass, header, options = {})
7777
end
7878

7979
cols = klass.columns
80-
cols = cols.sort_by(&:name) unless(options[:no_sort])
80+
cols = cols.sort_by(&:name) if(options[:sort])
8181
cols.each do |col|
8282
attrs = []
8383
attrs << "default(#{quote(col.default)})" unless col.default.nil?
@@ -92,7 +92,7 @@ def get_schema_info(klass, header, options = {})
9292
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
9393
end
9494
end
95-
95+
9696
# Check out if we got a geometric column
9797
# and print the type and SRID
9898
if col.respond_to?(:geometry_type)
@@ -207,13 +207,11 @@ def annotate_one_file(file_name, info_block, options={})
207207
end
208208
end
209209
end
210-
210+
211211
def remove_annotation_of_file(file_name)
212212
if File.exist?(file_name)
213213
content = File.read(file_name)
214-
215214
content.sub!(PATTERN, '')
216-
217215
File.open(file_name, "wb") { |f| f.puts content }
218216
end
219217
end
@@ -304,7 +302,7 @@ def get_model_files(options)
304302
end
305303
models
306304
end
307-
305+
308306
# Retrieve the classes belonging to the model names we're asked to process
309307
# Check for namespaced models in subdirectories as well as models
310308
# in subdirectories without namespacing.
@@ -340,9 +338,9 @@ def do_annotations(options={})
340338
version = ActiveRecord::Migrator.current_version rescue 0
341339
if version > 0
342340
header << "\n# Schema version: #{version}"
343-
end
341+
end
344342
end
345-
343+
346344
if options[:model_dir]
347345
self.model_dir = options[:model_dir]
348346
end
@@ -367,7 +365,7 @@ def do_annotations(options={})
367365
puts "Annotated (#{annotated.length}): #{annotated.join(', ')}"
368366
end
369367
end
370-
368+
371369
def remove_annotations(options={})
372370
if options[:model_dir]
373371
puts "removing"

lib/tasks/annotate_models.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ task :annotate_models => :environment do
2626
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
2727
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
2828
options[:format_markdown] = ENV['format_markdown'] =~ true_re
29-
options[:no_sort] = ENV['no_sort'] =~ true_re
29+
options[:sort] = ENV['sort'] =~ true_re
3030
options[:force] = ENV['force'] =~ true_re
3131
AnnotateModels.do_annotations(options)
3232
end

0 commit comments

Comments
 (0)