Module: RequireHooks::Bootsnap::LoadIseqExt
- Defined in:
- lib/require-hooks/mode/bootsnap.rb
Class Attribute Summary collapse
-
.orig_cache_dir ⇒ Object
Returns the value of attribute orig_cache_dir.
Instance Method Summary collapse
-
#load_iseq(path) ⇒ Object
Around hooks must be performed every time we trigger a file load, even if the file is already cached.
Class Attribute Details
.orig_cache_dir ⇒ Object
Returns the value of attribute orig_cache_dir.
55 56 57 |
# File 'lib/require-hooks/mode/bootsnap.rb', line 55 def orig_cache_dir @orig_cache_dir end |
Instance Method Details
#load_iseq(path) ⇒ Object
Around hooks must be performed every time we trigger a file load, even if the file is already cached.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/require-hooks/mode/bootsnap.rb', line 60 def load_iseq(path) ctx = RequireHooks.context_for(path) # Early-return for non-trackable paths if ctx.empty? ::Bootsnap::CompileCache::ISeq.cache_dir = LoadIseqExt.orig_cache_dir if LoadIseqExt.orig_cache_dir return super end LoadIseqExt.orig_cache_dir ||= ::Bootsnap::CompileCache::ISeq.cache_dir ::Bootsnap::CompileCache::ISeq.cache_dir = File.join(LoadIseqExt.orig_cache_dir, RequireHooks::Bootsnap.version_hash) ctx.run_around_load_callbacks(path) do iseq = super ::Bootsnap::CompileCache::ISeq.cache_dir = LoadIseqExt.orig_cache_dir # Bootsnap returns nil when the coverage is on, # we fallback to our custom #compile_with_coverage unless iseq next unless defined?(Coverage) && Coverage.running? iseq = RequireHooks::Iseq.compile_with_coverage(ctx, path) end iseq.eval EMPTY_ISEQ ensure ::Bootsnap::CompileCache::ISeq.cache_dir = LoadIseqExt.orig_cache_dir end end |