Skip to content

Commit 8db2310

Browse files
committed
Removes unnecessary calls to zeitwerk_enabled?
In Rails 7 zeitwerk_enabled? returns true unconditionally. It exists to let 3rd party code supporting multiple Rails versions check, but we no longer need to use it internally.
1 parent d9e188d commit 8db2310

File tree

4 files changed

+11
-36
lines changed

4 files changed

+11
-36
lines changed

railties/lib/rails/application.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,7 @@ def migration_railties # :nodoc:
513513

514514
# Eager loads the application code.
515515
def eager_load!
516-
if Rails.autoloaders.zeitwerk_enabled?
517-
Rails.autoloaders.each(&:eager_load)
518-
else
519-
super
520-
end
516+
Rails.autoloaders.each(&:eager_load)
521517
end
522518

523519
protected

railties/lib/rails/autoloaders.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,22 @@ class << self
99
include Enumerable
1010

1111
def main
12-
if zeitwerk_enabled?
13-
@main ||= Zeitwerk::Loader.new.tap do |loader|
14-
loader.tag = "rails.main"
15-
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
16-
end
12+
@main ||= Zeitwerk::Loader.new.tap do |loader|
13+
loader.tag = "rails.main"
14+
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
1715
end
1816
end
1917

2018
def once
21-
if zeitwerk_enabled?
22-
@once ||= Zeitwerk::Loader.new.tap do |loader|
23-
loader.tag = "rails.once"
24-
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
25-
end
19+
@once ||= Zeitwerk::Loader.new.tap do |loader|
20+
loader.tag = "rails.once"
21+
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
2622
end
2723
end
2824

2925
def each
30-
if zeitwerk_enabled?
31-
yield main
32-
yield once
33-
end
26+
yield main
27+
yield once
3428
end
3529

3630
def logger=(logger)

railties/lib/rails/engine.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,8 @@ def load_server(app = self)
482482
end
483483

484484
def eager_load!
485-
# Already done by Zeitwerk::Loader.eager_load_all. We need this guard to
486-
# easily provide a compatible API for both zeitwerk and classic modes.
487-
return if Rails.autoloaders.zeitwerk_enabled?
488-
489-
config.eager_load_paths.each do |load_path|
490-
# Starts after load_path plus a slash, ends before ".rb".
491-
relname_range = (load_path.to_s.length + 1)...-3
492-
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
493-
require_dependency file[relname_range]
494-
end
495-
end
485+
# Already done by Zeitwerk::Loader.eager_load_all. By now, we leave the
486+
# method as a no-op for backwards compatibility.
496487
end
497488

498489
def railties

railties/lib/rails/tasks/zeitwerk.rake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# frozen_string_literal: true
22

3-
ensure_zeitwerk_mode = ->() do
4-
unless Rails.autoloaders.zeitwerk_enabled?
5-
abort "Please, enable :zeitwerk mode in config/application.rb and try again."
6-
end
7-
end
8-
93
eager_load = ->() do
104
puts "Hold on, I am eager loading the application."
115
Zeitwerk::Loader.eager_load_all

0 commit comments

Comments
 (0)