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
|
# File 'lib/modules/loader.rb', line 30
def self.import(id, type=nil)
if type == 'interop'
return Interop.import(id, save_the_environment: @save_the_environment)
end
callsite = Callsite.resolve
parent = @import_called ? File.dirname(callsite) : @basepath
raw = File.join(parent, id)
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?(filepath)
rescue => e
raise LoadError, "Could not load #{filepath} from #{parent}: #{e}"
end
return @cache[filepath]
end
return Interop.import(id, save_the_environment: @save_the_environment)
end
|