mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Drops support for classic mode
This starts a series of patches in which we drop classic mode. The final result no longer has a const_missing callback, there is no hook/unhook, and so on. So, in this patch we remove the ability of configuring classic, but some of the code that remains will be further refactored.
This commit is contained in:
parent
7762770805
commit
0d523d8365
8 changed files with 12 additions and 94 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require "set"
|
require "set"
|
||||||
require "active_support/core_ext/string/inflections"
|
require "active_support/core_ext/string/inflections"
|
||||||
|
require "zeitwerk"
|
||||||
|
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
module Dependencies
|
module Dependencies
|
||||||
|
|
|
@ -438,25 +438,3 @@ While in common names these operations match, if acronyms or custom inflection r
|
||||||
### More Differences
|
### More Differences
|
||||||
|
|
||||||
There are some other subtle differences. Please check the [autoloading section](upgrading_ruby_on_rails.html#autoloading) of the _Upgrading Ruby on Rails_] guide for details.
|
There are some other subtle differences. Please check the [autoloading section](upgrading_ruby_on_rails.html#autoloading) of the _Upgrading Ruby on Rails_] guide for details.
|
||||||
|
|
||||||
Classic Mode is Deprecated
|
|
||||||
--------------------------
|
|
||||||
|
|
||||||
Currently, it is still possible to use `classic` mode. However, `classic` is deprecated and will be eventually removed.
|
|
||||||
|
|
||||||
New applications should use `zeitwerk` mode (which is the default), and applications being upgraded are strongly encouraged to migrate to `zeitwerk` mode. Please check the [_Upgrading Ruby on Rails_](upgrading_ruby_on_rails.html#autoloading) guide for details.
|
|
||||||
|
|
||||||
Opting Out
|
|
||||||
----------
|
|
||||||
|
|
||||||
Applications can load Rails 6 defaults and still use the `classic` autoloader this way:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
# config/application.rb
|
|
||||||
config.load_defaults 6.0
|
|
||||||
config.autoloader = :classic
|
|
||||||
```
|
|
||||||
|
|
||||||
That may be handy if upgrading to Rails 6 in different phases, but `classic` mode is discouraged for new applications.
|
|
||||||
|
|
||||||
`zeitwerk` mode is not available in versions of Rails prior to 6.0.
|
|
||||||
|
|
|
@ -159,13 +159,6 @@ numbers. It also filters out sensitive values of database columns when call `#in
|
||||||
|
|
||||||
* `config.time_zone` sets the default time zone for the application and enables time zone awareness for Active Record.
|
* `config.time_zone` sets the default time zone for the application and enables time zone awareness for Active Record.
|
||||||
|
|
||||||
* `config.autoloader` sets the autoloading mode. This option defaults to `:zeitwerk` when `config.load_defaults` is called with `6.0` or greater. Applications can still use the classic autoloader by setting this value to `:classic` after loading the framework defaults:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
config.load_defaults 6.0
|
|
||||||
config.autoloader = :classic
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configuring Assets
|
### Configuring Assets
|
||||||
|
|
||||||
* `config.assets.enabled` a flag that controls whether the asset
|
* `config.assets.enabled` a flag that controls whether the asset
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Rails
|
||||||
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
|
||||||
:rake_eager_load
|
:rake_eager_load
|
||||||
|
|
||||||
attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
|
attr_reader :encoding, :api_only, :loaded_config_version
|
||||||
|
|
||||||
def initialize(*)
|
def initialize(*)
|
||||||
super
|
super
|
||||||
|
@ -69,7 +69,6 @@ module Rails
|
||||||
@credentials = ActiveSupport::OrderedOptions.new
|
@credentials = ActiveSupport::OrderedOptions.new
|
||||||
@credentials.content_path = default_credentials_content_path
|
@credentials.content_path = default_credentials_content_path
|
||||||
@credentials.key_path = default_credentials_key_path
|
@credentials.key_path = default_credentials_key_path
|
||||||
@autoloader = :classic
|
|
||||||
@disable_sandbox = false
|
@disable_sandbox = false
|
||||||
@add_autoload_paths_to_load_path = true
|
@add_autoload_paths_to_load_path = true
|
||||||
@permissions_policy = nil
|
@permissions_policy = nil
|
||||||
|
@ -128,8 +127,6 @@ module Rails
|
||||||
when "6.0"
|
when "6.0"
|
||||||
load_defaults "5.2"
|
load_defaults "5.2"
|
||||||
|
|
||||||
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
|
|
||||||
|
|
||||||
if respond_to?(:action_view)
|
if respond_to?(:action_view)
|
||||||
action_view.default_enforce_utf8 = false
|
action_view.default_enforce_utf8 = false
|
||||||
end
|
end
|
||||||
|
@ -155,8 +152,6 @@ module Rails
|
||||||
when "6.1"
|
when "6.1"
|
||||||
load_defaults "6.0"
|
load_defaults "6.0"
|
||||||
|
|
||||||
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
|
|
||||||
|
|
||||||
if respond_to?(:active_record)
|
if respond_to?(:active_record)
|
||||||
active_record.has_many_inversing = true
|
active_record.has_many_inversing = true
|
||||||
active_record.legacy_connection_handling = false
|
active_record.legacy_connection_handling = false
|
||||||
|
@ -365,18 +360,6 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def autoloader=(autoloader)
|
|
||||||
case autoloader
|
|
||||||
when :classic
|
|
||||||
@autoloader = autoloader
|
|
||||||
when :zeitwerk
|
|
||||||
require "zeitwerk"
|
|
||||||
@autoloader = autoloader
|
|
||||||
else
|
|
||||||
raise ArgumentError, "config.autoloader may be :classic or :zeitwerk, got #{autoloader.inspect} instead"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def default_log_file
|
def default_log_file
|
||||||
path = paths["log"].first
|
path = paths["log"].first
|
||||||
unless File.exist? File.dirname path
|
unless File.exist? File.dirname path
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require "active_support/core_ext/string/inflections"
|
require "active_support/core_ext/string/inflections"
|
||||||
require "active_support/core_ext/array/conversions"
|
require "active_support/core_ext/array/conversions"
|
||||||
|
require "zeitwerk"
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
class Application
|
class Application
|
||||||
|
@ -39,14 +40,10 @@ module Rails
|
||||||
example = autoloaded.first
|
example = autoloaded.first
|
||||||
example_klass = example.constantize.class
|
example_klass = example.constantize.class
|
||||||
|
|
||||||
if config.autoloader == :zeitwerk
|
ActiveSupport::DescendantsTracker.clear
|
||||||
ActiveSupport::DescendantsTracker.clear
|
ActiveSupport::Dependencies.clear
|
||||||
ActiveSupport::Dependencies.clear
|
|
||||||
|
|
||||||
unload_message = "#{these} autoloaded #{constants} #{have} been unloaded."
|
unload_message = "#{these} autoloaded #{constants} #{have} been unloaded."
|
||||||
else
|
|
||||||
unload_message = "`config.autoloader` is set to `#{config.autoloader}`. #{these} autoloaded #{constants} would have been unloaded if `config.autoloader` had been set to `:zeitwerk`."
|
|
||||||
end
|
|
||||||
|
|
||||||
ActiveSupport::Deprecation.warn(<<~WARNING)
|
ActiveSupport::Deprecation.warn(<<~WARNING)
|
||||||
Initialization autoloaded the #{constants} #{enum}.
|
Initialization autoloaded the #{constants} #{enum}.
|
||||||
|
@ -76,10 +73,8 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer :let_zeitwerk_take_over do
|
initializer :let_zeitwerk_take_over do
|
||||||
if config.autoloader == :zeitwerk
|
require "active_support/dependencies/zeitwerk_integration"
|
||||||
require "active_support/dependencies/zeitwerk_integration"
|
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
|
||||||
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup default session store if not already set in config/application.rb
|
# Setup default session store if not already set in config/application.rb
|
||||||
|
@ -113,10 +108,7 @@ module Rails
|
||||||
initializer :eager_load! do
|
initializer :eager_load! do
|
||||||
if config.eager_load
|
if config.eager_load
|
||||||
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
||||||
# Checks defined?(Zeitwerk) instead of zeitwerk_enabled? because we
|
Zeitwerk::Loader.eager_load_all
|
||||||
# want to eager load any dependency managed by Zeitwerk regardless of
|
|
||||||
# the autoloading mode of the application.
|
|
||||||
Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
|
|
||||||
config.eager_load_namespaces.each(&:eager_load!)
|
config.eager_load_namespaces.each(&:eager_load!)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "active_support/dependencies/zeitwerk_integration"
|
require "active_support/dependencies/zeitwerk_integration"
|
||||||
|
require "zeitwerk"
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
module Autoloaders # :nodoc:
|
module Autoloaders # :nodoc:
|
||||||
|
@ -41,7 +42,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def zeitwerk_enabled?
|
def zeitwerk_enabled?
|
||||||
Rails.configuration.autoloader == :zeitwerk
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1219,7 +1219,6 @@ module ApplicationTests
|
||||||
test "autoloaders" do
|
test "autoloaders" do
|
||||||
app "development"
|
app "development"
|
||||||
|
|
||||||
config = Rails.application.config
|
|
||||||
assert Rails.autoloaders.zeitwerk_enabled?
|
assert Rails.autoloaders.zeitwerk_enabled?
|
||||||
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.main
|
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.main
|
||||||
assert_equal "rails.main", Rails.autoloaders.main.tag
|
assert_equal "rails.main", Rails.autoloaders.main.tag
|
||||||
|
@ -1228,24 +1227,6 @@ module ApplicationTests
|
||||||
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
|
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.main.inflector
|
||||||
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector
|
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector
|
||||||
|
|
||||||
config.autoloader = :classic
|
|
||||||
assert_not Rails.autoloaders.zeitwerk_enabled?
|
|
||||||
assert_nil Rails.autoloaders.main
|
|
||||||
assert_nil Rails.autoloaders.once
|
|
||||||
assert_equal 0, Rails.autoloaders.count
|
|
||||||
|
|
||||||
config.autoloader = :zeitwerk
|
|
||||||
assert Rails.autoloaders.zeitwerk_enabled?
|
|
||||||
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.main
|
|
||||||
assert_equal "rails.main", Rails.autoloaders.main.tag
|
|
||||||
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
|
end
|
||||||
|
|
||||||
test "config.action_view.cache_template_loading with cache_classes default" do
|
test "config.action_view.cache_template_loading with cache_classes default" do
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
|
||||||
deps.singleton_class < deps::ZeitwerkIntegration::Decorations
|
deps.singleton_class < deps::ZeitwerkIntegration::Decorations
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ActiveSupport::Dependencies is decorated by default" do
|
test "ActiveSupport::Dependencies is decorated" do
|
||||||
boot
|
boot
|
||||||
|
|
||||||
assert decorated?
|
assert decorated?
|
||||||
|
@ -36,17 +36,6 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
|
||||||
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
|
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ActiveSupport::Dependencies is not decorated in classic mode" do
|
|
||||||
add_to_config "config.autoloader = :classic"
|
|
||||||
boot
|
|
||||||
|
|
||||||
assert_not decorated?
|
|
||||||
assert_not Rails.autoloaders.zeitwerk_enabled?
|
|
||||||
assert_nil Rails.autoloaders.main
|
|
||||||
assert_nil Rails.autoloaders.once
|
|
||||||
assert_equal 0, Rails.autoloaders.count
|
|
||||||
end
|
|
||||||
|
|
||||||
test "autoloaders inflect with Active Support" do
|
test "autoloaders inflect with Active Support" do
|
||||||
app_file "config/initializers/inflections.rb", <<-RUBY
|
app_file "config/initializers/inflections.rb", <<-RUBY
|
||||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
|
|
Loading…
Reference in a new issue