Commit a1cc2a0f by cuong.tran

Add :ignore_unknown_models option to disable warnings about invalid model files, #251

parent 6523dd7d
......@@ -182,6 +182,10 @@ OptionParser.new do |opts|
ENV['hide_limit_column_types'] = "#{values}"
end
opts.on('--ignore-unknown-models', "don't display warnings for bad model files" ) do |values|
ENV['ignore_unknown_models'] = "true"
end
end.parse!
options = Annotate.setup_options({ :is_rake => ENV['is_rake'] && !ENV['is_rake'].empty? })
......
......@@ -27,7 +27,7 @@ module Annotate
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:timestamp, :exclude_serializers, :classified_sort, :show_foreign_keys,
:exclude_scaffolds, :exclude_controllers, :exclude_helpers
:exclude_scaffolds, :exclude_controllers, :exclude_helpers, :ignore_unknown_models,
]
OTHER_OPTIONS=[
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes,
......
......@@ -488,7 +488,7 @@ module AnnotateModels
model_path = file.gsub(/\.rb$/, '')
model_dir.each { |dir| model_path = model_path.gsub(/^#{dir}/, '').gsub(/^\//, '') }
begin
get_loaded_model(model_path) or raise LoadError.new("cannot load a model from #{file}")
get_loaded_model(model_path) or raise BadModelFileError.new
rescue LoadError
# this is for non-rails projects, which don't get Rails auto-require magic
file_path = File.expand_path(file)
......@@ -556,6 +556,11 @@ module AnnotateModels
annotated << file
end
end
rescue BadModelFileError => e
unless options[:ignore_unknown_models]
puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
......@@ -632,4 +637,10 @@ module AnnotateModels
$VERBOSE = old_verbose
end
end
class BadModelFileError < LoadError
def to_s
"file doesn't contain a valid model class"
end
end
end
......@@ -29,6 +29,7 @@ if Rails.env.development?
'exclude_helpers' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(',') %>',
'skip_on_db_migrate' => 'false',
'format_bare' => 'true',
......
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