aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/load_error.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/load_error.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/load_error.rb46
1 files changed, 16 insertions, 30 deletions
diff --git a/activesupport/lib/active_support/core_ext/load_error.rb b/activesupport/lib/active_support/core_ext/load_error.rb
index cc6287b100..615ebe9588 100644
--- a/activesupport/lib/active_support/core_ext/load_error.rb
+++ b/activesupport/lib/active_support/core_ext/load_error.rb
@@ -1,36 +1,22 @@
-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
+class LoadError
+ REGEXPS = [
+ /^no such file to load -- (.+)$/i,
+ /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
+ /^Missing API definition file in (.+)$/i,
+ ]
- def self.from_message(message)
- REGEXPS.each do |regexp, capture|
- match = regexp.match(message)
- return MissingSourceFile.new(message, match[capture]) unless match.nil?
+ def path
+ @path ||= begin
+ REGEXPS.find do |regex|
+ message =~ regex
+ end
+ $1
end
- nil
end
- REGEXPS = [
- [/^no such file to load -- (.+)$/i, 1],
- [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
- [/^Missing API definition file in (.+)$/i, 1],
- [/win32/, 0]
- ] unless defined?(REGEXPS)
-end
-
-class LoadError
- def self.new(*args)
- if self == LoadError
- MissingSourceFile.from_message(args.first)
- else
- super
- end
+ def is_missing?(location)
+ location.sub(/\.rb$/, '') == path.sub(/\.rb$/, '')
end
end
+
+MissingSourceFile = LoadError \ No newline at end of file