Module: Onload::BootsnapAutoloadPatch
- Included in:
- Module
- Defined in:
- lib/onload/ext/bootsnap/autoload.rb
Instance Method Summary collapse
Instance Method Details
#autoload(const, path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/onload/ext/bootsnap/autoload.rb', line 5 def autoload(const, path) # Bootsnap monkeypatches Module.autoload in order to leverage its load # path cache, which effectively converts a relative path into an absolute # one without incurring the cost of searching the load path. # Unfortunately, if an unprocessed file has already been transpiled, the # cache seems to always return the corresponding .rb file. Bootsnap's # autoload patch passes the .rb file to Ruby's original autoload, # effectively wiping out the previous autoload that pointed to the # unprocessed file. To fix this we have to intercept the cache lookup and # force autoloading the unprocessed file if one exists. cached_path = Bootsnap::LoadPathCache.load_path_cache.find(path) if (unprocessed_path = Onload.unprocessed_file_for(cached_path)) return super(const, unprocessed_path) end super end |