Module: Bootsnap::LoadPathCache::CoreExt::ActiveSupport::ClassMethods
- Included in:
- ActiveSupport::Dependencies
- Defined in:
- lib/bootsnap/load_path_cache/core_ext/active_support.rb
Instance Method Summary collapse
- #autoload_paths=(o) ⇒ Object
- #autoloadable_module?(path_suffix) ⇒ Boolean
-
#depend_on ⇒ Object
Signature has changed a few times over the years; easiest to not reiterate it with version polymorphism here…
-
#load_missing_constant(from_mod, const_name) ⇒ Object
If we can’t find a constant using the patched implementation of search_for_file, try again with the default implementation.
- #remove_constant(const) ⇒ Object
- #require_or_load ⇒ Object
- #search_for_file(path) ⇒ Object
Instance Method Details
#autoload_paths=(o) ⇒ Object
22 23 24 25 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 22 def autoload_paths=(o) super Bootsnap::LoadPathCache.autoload_paths_cache.reinitialize(o) end |
#autoloadable_module?(path_suffix) ⇒ Boolean
38 39 40 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 38 def autoloadable_module?(path_suffix) Bootsnap::LoadPathCache.autoload_paths_cache.load_dir(path_suffix) end |
#depend_on ⇒ Object
Signature has changed a few times over the years; easiest to not reiterate it with version polymorphism here…
81 82 83 84 85 86 87 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 81 def depend_on(*) super rescue LoadError # If we already had cache disabled, there's no use retrying raise if Thread.current[:without_bootsnap_cache] CoreExt::ActiveSupport.without_bootsnap_cache { super } end |
#load_missing_constant(from_mod, const_name) ⇒ Object
If we can’t find a constant using the patched implementation of search_for_file, try again with the default implementation.
These methods call search_for_file, and we want to modify its behaviour. The gymnastics here are a bit awkward, but it prevents 200+ lines of monkeypatches.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 58 def load_missing_constant(from_mod, const_name) CoreExt::ActiveSupport.allow_bootsnap_retry(false) do super end rescue NameError => e # This function can end up called recursively, we only want to # retry at the top-level. raise if Thread.current[:without_bootsnap_retry] # If we already had cache disabled, there's no use retrying raise if Thread.current[:without_bootsnap_cache] # NoMethodError is a NameError, but we only want to handle actual # NameError instances. raise unless e.class == NameError # We can only confidently handle cases when *this* constant fails # to load, not other constants referred to by it. raise unless e.name == const_name # If the constant was actually loaded, something else went wrong? raise if from_mod.const_defined?(const_name) CoreExt::ActiveSupport.without_bootsnap_cache { super } end |
#remove_constant(const) ⇒ Object
42 43 44 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 42 def remove_constant(const) CoreExt::ActiveSupport.without_bootsnap_cache { super } end |
#require_or_load ⇒ Object
46 47 48 49 50 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 46 def require_or_load(*) CoreExt::ActiveSupport.allow_bootsnap_retry(true) do super end end |
#search_for_file(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bootsnap/load_path_cache/core_ext/active_support.rb', line 27 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 |