Module: Kernel
- Defined in:
- lib/bootsnap/load_path_cache/core_ext/kernel_require.rb
Class Method Summary collapse
- .load(path, wrap = false) ⇒ Object
- .load_without_bootsnap ⇒ Object
- .require(path) ⇒ Object
- .require_relative(path) ⇒ Object
- .require_relative_without_bootsnap ⇒ Object
-
.require_with_bootsnap_lfi(path, resolved = nil) ⇒ Object
Note that require registers to $LOADED_FEATURES while load does not.
- .require_without_bootsnap ⇒ Object
Class Method Details
.load(path, wrap = false) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 57 def load(path, wrap = false) if (resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)) return load_without_bootsnap(resolved, wrap) end # load also allows relative paths from pwd even when not in $: if File.exist?(relative = File.(path).freeze) return load_without_bootsnap(relative, wrap) end raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path)) rescue LoadError => e e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true) raise(e) rescue Bootsnap::LoadPathCache::ReturnFalse false rescue Bootsnap::LoadPathCache::FallbackScan fallback = true ensure if fallback load_without_bootsnap(path, wrap) end end |
.load_without_bootsnap ⇒ Object
56 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 56 alias_method(:load_without_bootsnap, :load) |
.require(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 27 def require(path) return false if Bootsnap::LoadPathCache.loaded_features_index.key?(path) if (resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)) return require_with_bootsnap_lfi(path, resolved) end raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path)) rescue LoadError => e e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true) raise(e) rescue Bootsnap::LoadPathCache::ReturnFalse false rescue Bootsnap::LoadPathCache::FallbackScan fallback = true ensure if fallback require_with_bootsnap_lfi(path) end end |
.require_relative(path) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 49 def require_relative(path) realpath = Bootsnap::LoadPathCache.realpath_cache.call( caller_locations(1..1).first.absolute_path, path ) require(realpath) end |
.require_relative_without_bootsnap ⇒ Object
48 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 48 alias_method(:require_relative_without_bootsnap, :require_relative) |
.require_with_bootsnap_lfi(path, resolved = nil) ⇒ Object
Note that require registers to $LOADED_FEATURES while load does not.
21 22 23 24 25 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 21 def require_with_bootsnap_lfi(path, resolved = nil) Bootsnap::LoadPathCache.loaded_features_index.register(path, resolved) do require_without_bootsnap(resolved || path) end end |
.require_without_bootsnap ⇒ Object
18 |
# File 'lib/bootsnap/load_path_cache/core_ext/kernel_require.rb', line 18 alias_method(:require_without_bootsnap, :require) |