module Bootsnap::LoadPathCache::CoreExt::ActiveSupport::ClassMethods
def autoload_paths=(o)
def autoload_paths=(o) super Bootsnap::LoadPathCache.autoload_paths_cache.reinitialize(o) end
def autoloadable_module?(path_suffix)
def autoloadable_module?(path_suffix) Bootsnap::LoadPathCache.autoload_paths_cache.load_dir(path_suffix) end
def depend_on(*)
Signature has changed a few times over the years; easiest to not
def depend_on(*) super rescue LoadError => e raise(e) if e.instance_variable_defined?(Bootsnap::LoadPathCache::ERROR_TAG_IVAR) e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true) # If we already had cache disabled, there's no use retrying raise(e) if Thread.current[:without_bootsnap_cache] CoreExt::ActiveSupport.without_bootsnap_cache { super } end
def load_missing_constant(from_mod, const_name)
behaviour. The gymnastics here are a bit awkward, but it prevents
These methods call search_for_file, and we want to modify its
search_for_file, try again with the default implementation.
If we can't find a constant using the patched implementation of
def load_missing_constant(from_mod, const_name) CoreExt::ActiveSupport.allow_bootsnap_retry(false) do super end rescue NameError => e raise(e) if e.instance_variable_defined?(Bootsnap::LoadPathCache::ERROR_TAG_IVAR) e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true) # This function can end up called recursively, we only want to # retry at the top-level. raise(e) if Thread.current[:without_bootsnap_retry] # If we already had cache disabled, there's no use retrying raise(e) if Thread.current[:without_bootsnap_cache] # NoMethodError is a NameError, but we only want to handle actual # NameError instances. raise(e) unless e.class == NameError # We can only confidently handle cases when *this* constant fails # to load, not other constants referred to by it. raise(e) unless e.name == const_name # If the constant was actually loaded, something else went wrong? raise(e) if from_mod.const_defined?(const_name) CoreExt::ActiveSupport.without_bootsnap_cache { super } end
def remove_constant(const)
def remove_constant(const) CoreExt::ActiveSupport.without_bootsnap_cache { super } end
def require_or_load(*)
def require_or_load(*) CoreExt::ActiveSupport.allow_bootsnap_retry(true) do super end end
def search_for_file(path)
def search_for_file(path) return super if Thread.current[:without_bootsnap_cache] begin Bootsnap::LoadPathCache.autoload_paths_cache.find(path) rescue Bootsnap::LoadPathCache::ReturnFalse nil # doesn't really apply here rescue Bootsnap::LoadPathCache::FallbackScan nil # doesn't really apply here end end