1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

depend on Zeitwerk 2

This commit is contained in:
Xavier Noria 2019-04-07 12:30:34 +02:00
parent c9e4c848ee
commit 57c7cbb162
6 changed files with 28 additions and 7 deletions

View file

@ -71,7 +71,7 @@ PATH
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 1.4, >= 1.4.3)
zeitwerk (~> 2.0)
rails (6.0.0.beta3)
actioncable (= 6.0.0.beta3)
actionmailbox (= 6.0.0.beta3)
@ -526,7 +526,7 @@ GEM
websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (1.4.3)
zeitwerk (2.0.0)
PLATFORMS
java

View file

@ -1,3 +1,9 @@
* Depends on Zeitwerk 2, which stores less metadata if reloading is disabled
and hence uses less memory when `config.cache_classes` is `true`, a standard
setup in production.
*Xavier Noria*
* In `:zeitwerk` mode, eager load directories in engines and applications only
if present in their respective `config.eager_load_paths`.

View file

@ -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", "~> 1.4", ">= 1.4.3"
s.add_dependency "zeitwerk", "~> 2.0"
end

View file

@ -51,15 +51,15 @@ module ActiveSupport
end
class << self
def take_over
setup_autoloaders
def take_over(enable_reloading:)
setup_autoloaders(enable_reloading)
freeze_paths
decorate_dependencies
end
private
def setup_autoloaders
def setup_autoloaders(enable_reloading)
Dependencies.autoload_paths.each do |autoload_path|
# Zeitwerk only accepts existing directories in `push_dir` to
# prevent misconfigurations.
@ -72,6 +72,7 @@ module ActiveSupport
autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
end
Rails.autoloaders.main.enable_reloading if enable_reloading
Rails.autoloaders.each(&:setup)
end

View file

@ -24,7 +24,7 @@ module Rails
initializer :let_zeitwerk_take_over do
if config.autoloader == :zeitwerk
require "active_support/dependencies/zeitwerk_integration"
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
end
end

View file

@ -131,6 +131,20 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert $zeitwerk_integration_test_post
end
test "reloading is enabled if config.cache_classes is false" do
boot
assert Rails.autoloaders.main.reloading_enabled?
assert_not Rails.autoloaders.once.reloading_enabled?
end
test "reloading is disabled if config.cache_classes is true" do
boot("production")
assert_not Rails.autoloaders.main.reloading_enabled?
assert_not Rails.autoloaders.once.reloading_enabled?
end
test "eager loading loads code in engines" do
$test_blog_engine_eager_loaded = false