Commit f96592dc by Jon Frisby

Wider type column output, play nice with Rake CLI.

parent 809a29f9
== HEAD
* Widen type column so we can handle longtexts with chopping things off.
* Skip trying to get list of models from commandline when running via Rake (was
preventing the use of multiple rake tasks in one command if one of them was
db:migrate).
* Add ability to skip annotations for a model by adding
'# -*- SkipSchemaAnnotations' anywhere in the file.
* Don't show column limits for integer and boolean types.
......
......@@ -61,7 +61,7 @@ module AnnotateModels
info<< "#\n"
max_size = klass.column_names.map{|name| name.size}.max || 0
max_size += ENV['format_rdoc'] ? 5 : 1
max_size += options[:format_rdoc] ? 5 : 1
klass.columns.sort_by(&:name).each do |col|
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
......@@ -95,10 +95,10 @@ module AnnotateModels
end
end
if ENV['format_rdoc']
if options[:format_rdoc]
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col.name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
else
info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
info << sprintf("# %-#{max_size}.#{max_size}s:%-16.16s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
end
end
......@@ -106,7 +106,7 @@ module AnnotateModels
info << get_index_info(klass)
end
if ENV['format_rdoc']
if options[:format_rdoc]
info << "#--\n"
info << "# #{END_MARK}\n"
info << "#++\n\n"
......@@ -246,9 +246,13 @@ module AnnotateModels
# the underscore or CamelCase versions of model names.
# Otherwise we take all the model files in the
# model_dir directory.
def get_model_files
def get_model_files(options)
if(!options[:is_rake])
models = ARGV.dup
models.shift
else
models = []
end
models.reject!{|m| m.match(/^(.*)=/)}
if models.empty?
begin
......@@ -308,10 +312,10 @@ module AnnotateModels
end
annotated = []
get_model_files.each do |file|
get_model_files(options).each do |file|
begin
klass = get_model_class(file)
if klass < ActiveRecord::Base && !klass.abstract_class?
if klass && klass < ActiveRecord::Base && !klass.abstract_class?
if annotate(klass, file, header, options)
annotated << klass
end
......@@ -333,7 +337,7 @@ module AnnotateModels
self.model_dir = options[:model_dir]
end
deannotated = []
get_model_files.each do |file|
get_model_files(options).each do |file|
begin
klass = get_model_class(file)
if klass < ActiveRecord::Base && !klass.abstract_class?
......
......@@ -13,5 +13,4 @@ if(Rails.env.development?)
ENV['exclude_fixtures'] = "false"
ENV['skip_on_db_migrate'] = "false"
ENV['format_rdoc'] = "false"
ENV['format_bare'] = "true"
end
......@@ -5,7 +5,7 @@ task :annotate_models => :environment do
true_re = /(true|t|yes|y|1)$/i
options={}
options={ :is_rake => true }
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
......@@ -16,6 +16,7 @@ task :annotate_models => :environment do
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
AnnotateModels.do_annotations(options)
end
......@@ -23,7 +24,7 @@ desc "Remove schema information from model and fixture files"
task :remove_annotation => :environment do
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'active_record_patch'))
options={}
options={ :is_rake => true }
options[:model_dir] = ENV['model_dir']
AnnotateModels.remove_annotations(options)
end
......@@ -60,8 +60,7 @@ EOS
mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50)
])
ENV.stub!(:[]).with('format_rdoc').and_return(true)
AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX).should eql(<<-EOS)
AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, :format_rdoc => true).should eql(<<-EOS)
# #{AnnotateModels::PREFIX}
#
# Table name: users
......
......@@ -2,4 +2,3 @@ TODO
-----
add "top" and "bottom" as synonyms for "before" and "after"
change 'exclude' to 'only' (double negatives are not unconfusing)
make format_* options go through normal channel for options
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