Skip to content

Commit

Permalink
Catch possible exceptions when annotating a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJoy committed Aug 22, 2012
1 parent b1882bc commit a19d2cd
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions lib/annotate/annotate_models.rb
Expand Up @@ -260,39 +260,44 @@ def remove_annotation_of_file(file_name)
# :exclude_factories<Symbol>:: whether to skip modification of factory files
#
def annotate(klass, file, header, options={})
info = get_schema_info(klass, header, options)
did_annotate = false
model_name = klass.name.underscore
table_name = klass.table_name
model_file_name = File.join(model_dir, file)

if annotate_one_file(model_file_name, info, options_with_position(options, :position_in_class))
did_annotate = true
end
begin
info = get_schema_info(klass, header, options)
did_annotate = false
model_name = klass.name.underscore
table_name = klass.table_name
model_file_name = File.join(model_dir, file)

if annotate_one_file(model_file_name, info, options_with_position(options, :position_in_class))
did_annotate = true
end

unless options[:exclude_tests]
did_annotate = TEST_PATTERNS.
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }.
map { |pat| find_test_file(*pat) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_test)) }.
detect { |result| result } || did_annotate
end
unless options[:exclude_tests]
did_annotate = TEST_PATTERNS.
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }.
map { |pat| find_test_file(*pat) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_test)) }.
detect { |result| result } || did_annotate
end

unless options[:exclude_fixtures]
did_annotate = FIXTURE_PATTERNS.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) }.
detect { |result| result } || did_annotate
end
unless options[:exclude_fixtures]
did_annotate = FIXTURE_PATTERNS.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) }.
detect { |result| result } || did_annotate
end

unless options[:exclude_factories]
did_annotate = FACTORY_PATTERNS.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_factory)) }.
detect { |result| result } || did_annotate
end
unless options[:exclude_factories]
did_annotate = FACTORY_PATTERNS.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_factory)) }.
detect { |result| result } || did_annotate
end

return did_annotate
return did_annotate
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end
end

# position = :position_in_fixture or :position_in_class
Expand Down

0 comments on commit a19d2cd

Please sign in to comment.