Commit 0f978c57 by Alex Chaffee

improve error handling and documentation

parent 68f951d8
...@@ -6,7 +6,7 @@ require 'annotate' ...@@ -6,7 +6,7 @@ require 'annotate'
task = :annotate_models task = :annotate_models
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: annotate [options]" opts.banner = "Usage: annotate [options] [model_file]*"
opts.on('-d', '--delete', opts.on('-d', '--delete',
"Remove annotations from all model files") do "Remove annotations from all model files") do
......
...@@ -178,8 +178,15 @@ module AnnotateModels ...@@ -178,8 +178,15 @@ module AnnotateModels
models.shift models.shift
models.reject!{|m| m.starts_with?("position=")} models.reject!{|m| m.starts_with?("position=")}
if models.empty? if models.empty?
Dir.chdir(model_dir) do begin
models = Dir["**/*.rb"] 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
end end
models models
...@@ -194,7 +201,7 @@ module AnnotateModels ...@@ -194,7 +201,7 @@ module AnnotateModels
parts = model.split('::') parts = model.split('::')
begin begin
parts.inject(Object) {|klass, part| klass.const_get(part) } parts.inject(Object) {|klass, part| klass.const_get(part) }
rescue LoadError rescue LoadError, NameError
Object.const_get(parts.last) Object.const_get(parts.last)
end end
end end
...@@ -233,7 +240,8 @@ module AnnotateModels ...@@ -233,7 +240,8 @@ module AnnotateModels
end end
end end
rescue Exception => e rescue Exception => e
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})" puts "Unable to annotate #{file}: #{e.inspect}"
puts ""
end end
end end
if annotated.empty? if annotated.empty?
......
...@@ -7,7 +7,7 @@ task :annotate_models => :environment do ...@@ -7,7 +7,7 @@ task :annotate_models => :environment do
options[:show_indexes] = ENV['show_indexes'] options[:show_indexes] = ENV['show_indexes']
options[:model_dir] = ENV['model_dir'] options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version'] options[:include_version] = ENV['include_version']
options[:require] = ENV['require'].split(',') options[:require] = ENV['require'] ? ENV['require'].split(',') : nil
AnnotateModels.do_annotations(options) AnnotateModels.do_annotations(options)
end 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