diff options
author | Xavier Noria <fxn@hashref.com> | 2019-03-30 08:38:41 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2019-03-30 09:33:48 +0100 |
commit | 278f0dfeac03e9e9d57eae8f4618ff94d8584abe (patch) | |
tree | 5a81fac64ab373ff86f3b6f3499a1c175ad705e9 /activesupport/lib | |
parent | 360ff0a5934e32f49a2328b32b413ff58d6d79f1 (diff) | |
download | rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.tar.gz rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.tar.bz2 rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.zip |
fixes eager loading edge case in :zeitwerk mode
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies/zeitwerk_integration.rb | 20 |
2 files changed, 18 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index d5d00b5e6e..82f07c085e 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -70,6 +70,11 @@ module ActiveSupport #:nodoc: # only once. All directories in this set must also be present in +autoload_paths+. mattr_accessor :autoload_once_paths, default: [] + # This is a private set that collects all eager load paths during bootstrap. + # Useful for Zeitwerk integration. Its public interface is the config.* path + # accessors of each engine. + mattr_accessor :_eager_load_paths, default: Set.new + # An array of qualified constant names that have been loaded. Adding a name # to this array will cause it to be unloaded the next time Dependencies are # cleared. diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb index c6fdade006..a43d03cf09 100644 --- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb +++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "set" require "active_support/core_ext/string/inflections" module ActiveSupport @@ -52,7 +53,7 @@ module ActiveSupport class << self def take_over setup_autoloaders - freeze_autoload_paths + freeze_paths decorate_dependencies end @@ -64,11 +65,11 @@ module ActiveSupport # prevent misconfigurations. next unless File.directory?(autoload_path) - if autoload_once?(autoload_path) - Rails.autoloaders.once.push_dir(autoload_path) - else - Rails.autoloaders.main.push_dir(autoload_path) - end + autoloader = \ + autoload_once?(autoload_path) ? Rails.autoloaders.once : Rails.autoloaders.main + + autoloader.push_dir(autoload_path) + autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path) end Rails.autoloaders.each(&:setup) @@ -78,9 +79,14 @@ module ActiveSupport Dependencies.autoload_once_paths.include?(autoload_path) end - def freeze_autoload_paths + def eager_load?(autoload_path) + Dependencies._eager_load_paths.member?(autoload_path) + end + + def freeze_paths Dependencies.autoload_paths.freeze Dependencies.autoload_once_paths.freeze + Dependencies._eager_load_paths.freeze end def decorate_dependencies |