Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Can't rescue CompilationError directly: must check the exception's cl…
…ass name instead.

CompilationError is only available if RubyInline was loaded.
  • Loading branch information
francois committed Mar 11, 2008
1 parent 5d91a9c commit fb6dccc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/technoweenie/attachment_fu.rb
Expand Up @@ -84,19 +84,35 @@ def has_attachment(options = {})
processor_mod = Technoweenie::AttachmentFu::Processors.const_get(attachment_options[:processor])
include processor_mod unless included_modules.include?(processor_mod)
end
rescue LoadError, MissingSourceFile, CompilationError
rescue Object, Exception
raise unless load_related_exception?($!)

processors.shift
retry
end
else
begin
processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
include processor_mod unless included_modules.include?(processor_mod)
rescue LoadError, MissingSourceFile, CompilationError
rescue Object, Exception
raise unless load_related_exception?($!)

puts "Problems loading #{options[:processor]}Processor: #{$!}"
end
end unless parent_options[:processor] # Don't let child override processor
end

def load_related_exception?(e) #:nodoc: implementation specific
case
when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError"
# We can't rescue CompilationError directly, as it is part of the RubyInline library.
# We must instead rescue RuntimeError, and check the class' name.
true
else
false
end
end
private :load_related_exception?
end

module ClassMethods
Expand Down

0 comments on commit fb6dccc

Please sign in to comment.