25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/loader.rb', line 25
def self.import(id, type=nil)
if type == 'interop'
return Interop.import(id)
end
prev = @path
if @path.nil?
container = @basepath
raw = File.join(container, id)
else
container = File.dirname(@path)
raw = File.join(container, id)
end
@path = File.expand_path(raw)
filepath = @path.end_with?('.rb') ? @path : "#{@path}.rb"
exists = File.exist?(filepath)
if type == 'internal' && !exists
raise "Could not resolve local module at #{@path}"
end
if exists
begin
Kernel.load(filepath, true) unless @cache.include?(@path)
rescue
raise LoadError, "Could not load #{filepath} from #{container}"
end
result = @cache[@path]
else
result = Interop.import(id)
end
@path = prev
result
end
|