Commit 0f978c57 by Alex Chaffee

improve error handling and documentation

parent 68f951d8
......@@ -6,7 +6,7 @@ require 'annotate'
task = :annotate_models
OptionParser.new do |opts|
opts.banner = "Usage: annotate [options]"
opts.banner = "Usage: annotate [options] [model_file]*"
opts.on('-d', '--delete',
"Remove annotations from all model files") do
......
......@@ -178,8 +178,15 @@ module AnnotateModels
models.shift
models.reject!{|m| m.starts_with?("position=")}
if models.empty?
Dir.chdir(model_dir) do
models = Dir["**/*.rb"]
begin
Dir.chdir(model_dir) do
models = Dir["**/*.rb"]
end
rescue SystemCallError
puts "No models found in directory '#{model_dir}'."
puts "Either specify models on the command line, or use the --model-dir option."
puts "Call 'annotate --help' for more info."
exit 1;
end
end
models
......@@ -194,7 +201,7 @@ module AnnotateModels
parts = model.split('::')
begin
parts.inject(Object) {|klass, part| klass.const_get(part) }
rescue LoadError
rescue LoadError, NameError
Object.const_get(parts.last)
end
end
......@@ -233,7 +240,8 @@ module AnnotateModels
end
end
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})"
puts "Unable to annotate #{file}: #{e.inspect}"
puts ""
end
end
if annotated.empty?
......
......@@ -7,7 +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[:require] = ENV['require'].split(',')
options[:require] = ENV['require'] ? ENV['require'].split(',') : nil
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