From 1b2efe5a111941d57edbaf2be7f3a94eb02b5f9d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 23 Apr 2019 00:36:14 +0200 Subject: upgrades Zeitwerk to 2.1.4 This commit more or less undoes 9b5401f, restores autoloaded? not to touch the descendants tracker, and autoloaded_constants because it is documented in the guide. --- .../lib/active_support/dependencies/zeitwerk_integration.rb | 9 +++++++-- activesupport/lib/active_support/descendants_tracker.rb | 11 ++--------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3