2007-01-22 14:43:50 +01:00
|
|
|
class MissingSourceFile < LoadError #:nodoc:
|
|
|
|
attr_reader :path
|
|
|
|
def initialize(message, path)
|
|
|
|
super(message)
|
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_missing?(path)
|
|
|
|
path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def self.from_message(message)
|
|
|
|
REGEXPS.each do |regexp, capture|
|
|
|
|
match = regexp.match(message)
|
|
|
|
return MissingSourceFile.new(message, match[capture]) unless match.nil?
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
REGEXPS = [
|
|
|
|
[/^no such file to load -- (.+)$/i, 1],
|
|
|
|
[/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
|
|
|
|
[/^Missing API definition file in (.+)$/i, 1]
|
2007-02-09 09:04:31 +01:00
|
|
|
] unless defined?(REGEXPS)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
module ActiveSupport #:nodoc:
|
|
|
|
module CoreExtensions #:nodoc:
|
|
|
|
module LoadErrorExtensions #:nodoc:
|
|
|
|
module LoadErrorClassMethods #:nodoc:
|
|
|
|
def new(*args)
|
|
|
|
(self == LoadError && MissingSourceFile.from_message(args.first)) || super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::LoadError.extend(LoadErrorClassMethods)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|