diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2019-03-08 16:48:52 +0100 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2019-03-08 17:31:29 +0100 |
commit | 6d624f2de94623b4e94375edb882ae0ccfc0cb88 (patch) | |
tree | 8f3679839ebdcf5780f7abf68a82c90d0298fdcc | |
parent | 199de6bee261dd816b68c841c7775fdcd02b68d2 (diff) | |
download | rails-6d624f2de94623b4e94375edb882ae0ccfc0cb88.tar.gz rails-6d624f2de94623b4e94375edb882ae0ccfc0cb88.tar.bz2 rails-6d624f2de94623b4e94375edb882ae0ccfc0cb88.zip |
Allow autoloader inflectors to be swaped out
-rw-r--r-- | activesupport/lib/active_support/dependencies/zeitwerk_integration.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/autoloaders.rb | 10 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 4 |
4 files changed, 13 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb index ca4385b7c2..1e697e1ba5 100644 --- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb +++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb @@ -55,10 +55,6 @@ module ActiveSupport private def setup_autoloaders - Rails.autoloaders.each do |autoloader| - autoloader.inflector = Inflector - end - Dependencies.autoload_paths.each do |autoload_path| # Zeitwerk only accepts existing directories in `push_dir` to # prevent misconfigurations. diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 1f533a8c04..663960bb77 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -6,6 +6,7 @@ require "pathname" require "active_support" require "active_support/dependencies/autoload" +require "active_support/dependencies/zeitwerk_integration" require "active_support/core_ext/kernel/reporting" require "active_support/core_ext/module/delegation" require "active_support/core_ext/array/extract_options" diff --git a/railties/lib/rails/autoloaders.rb b/railties/lib/rails/autoloaders.rb index a6974cc207..36444ef05e 100644 --- a/railties/lib/rails/autoloaders.rb +++ b/railties/lib/rails/autoloaders.rb @@ -7,13 +7,19 @@ module Rails def main if zeitwerk_enabled? - @main ||= Zeitwerk::Loader.new.tap { |loader| loader.tag = "rails.main" } + @main ||= Zeitwerk::Loader.new.tap do |loader| + loader.tag = "rails.main" + loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector + end end end def once if zeitwerk_enabled? - @once ||= Zeitwerk::Loader.new.tap { |loader| loader.tag = "rails.once" } + @once ||= Zeitwerk::Loader.new.tap do |loader| + loader.tag = "rails.once" + loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector + end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 73773602a3..9ba5517afd 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1167,6 +1167,8 @@ module ApplicationTests assert_instance_of Zeitwerk::Loader, Rails.autoloaders.once assert_equal "rails.once", Rails.autoloaders.once.tag assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a + assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.main.inflector + assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector config.autoloader = :classic assert_not Rails.autoloaders.zeitwerk_enabled? @@ -1181,6 +1183,8 @@ module ApplicationTests assert_instance_of Zeitwerk::Loader, Rails.autoloaders.once assert_equal "rails.once", Rails.autoloaders.once.tag assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a + assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.main.inflector + assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector assert_raises(ArgumentError) { config.autoloader = :unknown } end |