diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/activesupport.gemspec | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies/zeitwerk_integration.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/descendants_tracker.rb | 11 |
3 files changed, 10 insertions, 12 deletions
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index dd2340cdd3..7ecbafc911 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |s| s.add_dependency "tzinfo", "~> 1.1" s.add_dependency "minitest", "~> 5.1" s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2" - s.add_dependency "zeitwerk", "~> 2.1", ">= 2.1.2" + s.add_dependency "zeitwerk", "~> 2.1", ">= 2.1.4" end diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb index d5dc7c2ff4..fd39ad6e55 100644 --- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb +++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb @@ -23,8 +23,13 @@ module ActiveSupport ActiveSupport::Inflector.safe_constantize(cpath) end - def to_unload?(cpath) - Rails.autoloaders.main.to_unload?(cpath) + def autoloaded_constants + Rails.autoloaders.main.unloadable_cpaths + end + + def autoloaded?(object) + cpath = object.is_a?(Module) ? object.name : object.to_s + Rails.autoloaders.main.unloadable_cpath?(cpath) end def verbose=(verbose) diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index fe0c6991aa..21565138a7 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -22,18 +22,11 @@ module ActiveSupport def clear if defined? ActiveSupport::Dependencies - # to_unload? is only defined in Zeitwerk mode. - to_unload = if Dependencies.respond_to?(:to_unload?) - ->(klass) { Dependencies.to_unload?(klass.name) } - else - ->(klass) { Dependencies.autoloaded?(klass) } - end - @@direct_descendants.each do |klass, descendants| - if to_unload[klass] + if Dependencies.autoloaded?(klass) @@direct_descendants.delete(klass) else - descendants.reject! { |v| to_unload[v] } + descendants.reject! { |v| Dependencies.autoloaded?(v) } end end else |