module Loader
Constants
- DEBUG
Public Class Methods
delete(id)
click to toggle source
# File lib/modules/loader.rb, line 56 def self.delete(id) filepath, exists = resolve_callsite(id) @cache.delete(exists ? filepath : id) end
export(value)
click to toggle source
# File lib/modules/loader.rb, line 20 def self.export(value) callsite = Callsite.resolve if @cache.include?(callsite) && value.class == Hash # Special handling to enable multiple exports @cache[callsite] = @cache[callsite].merge(value) else @cache[callsite] = value end end
import(id, type=nil)
click to toggle source
# 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 filepath, exists, parent = resolve_callsite(id) if type == 'internal' && !exists raise "Could not resolve local module at #{path}" end if exists # Prefer loading local module since we found it. 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 # Failover to external load. return Interop.import(id, save_the_environment: @save_the_environment) end
Private Class Methods
resolve_callsite(id)
click to toggle source
# File lib/modules/loader.rb, line 92 def self.resolve_callsite(id) callsite = Callsite.resolve(2) 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) [filepath, exists, parent] end