lib/polyglot.rb in polyglot-0.2.7 vs lib/polyglot.rb in polyglot-0.2.8
- old
+ new
@@ -2,13 +2,20 @@
require 'pathname'
module Polyglot
@registrations ||= {} # Guard against reloading
@loaded ||= {}
-
- class PolyglotLoadError < LoadError; end
+ class NestedLoadError < LoadError
+ def initialize le
+ @le = le
+ end
+ def reraise
+ raise @le
+ end
+ end
+
def self.register(extension, klass)
extension = [extension] unless Enumerable === extension
extension.each{|e|
@registrations[e] = klass
}
@@ -34,18 +41,22 @@
file = a[0].to_str
return if @loaded[file] # Check for $: changes or file time changes and reload?
begin
source_file, loader = Polyglot.find(file, *a[1..-1], &b)
if (loader)
- loader.load(source_file)
- @loaded[file] = true
+ begin
+ loader.load(source_file)
+ @loaded[file] = true
+ rescue LoadError => e
+ raise Polyglot::NestedLoadError.new(e)
+ end
else
msg = "Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}"
if defined?(MissingSourceFile)
raise MissingSourceFile.new(msg, file)
else
- raise PolyglotLoadError.new(msg)
+ raise LoadError.new(msg)
end
end
end
end
end
@@ -56,10 +67,12 @@
def require(*a, &b)
polyglot_original_require(*a, &b)
rescue LoadError => load_error
begin
Polyglot.load(*a, &b)
- rescue Polyglot::PolyglotLoadError
+ rescue Polyglot::NestedLoadError => e
+ e.reraise
+ rescue LoadError
# Raise the original exception, possibly a MissingSourceFile with a path
raise load_error
end
end
end