Commit 96e2cb57 by Tony Day

Include option to sort columns alphabetically.

parent 8ecd23ee
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
%w[rubygems rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
require File.dirname(__FILE__) + '/lib/annotate'
# Generate all the Rake tasks
......
......@@ -13,6 +13,7 @@ OptionParser.new do |opts|
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('-i', '--show-indexes', "List the table's database indexes in the annotation") { ENV['show_indexes'] = "yes" }
opts.on('-s', '--sort', "Sort columns alphabetically (rather than listing in creation order)") { ENV['sort'] = "yes" }
opts.on('--model-dir dir', "Annotate model files stored in dir rather than app/models") {|dir| ENV['model_dir'] = dir }
end.parse!
......@@ -20,4 +21,4 @@ if Annotate.load_tasks
Rake::Task[task].invoke
else
STDERR.puts "Can't find Rakefile. Are we in a Rails folder?"
end
\ No newline at end of file
end
......@@ -43,6 +43,7 @@ module AnnotateModels
info << "# Table name: #{klass.table_name}\n#\n"
max_size = klass.column_names.collect{|name| name.size}.max + 1
cols = []
klass.columns.each do |col|
attrs = []
attrs << "default(#{quote(col.default)})" if col.default
......@@ -62,8 +63,10 @@ module AnnotateModels
attrs << "#{col.geometry_type}, #{col.srid}"
end
info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
cols << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
end
cols.sort! if options[:sort]
info << cols.join
if options[:show_indexes]
info << get_index_info(klass)
......
......@@ -7,6 +7,7 @@ task :annotate_models => :environment do
options[:show_indexes] = ENV['show_indexes']
options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version']
options[:sort] = ENV['sort']
AnnotateModels.do_annotations(options)
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