Commit f96592dc by Jon Frisby

Wider type column output, play nice with Rake CLI.

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