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.
This commit is contained in:
parent
d9e188dbab
commit
8db23109bf
|
@ -513,11 +513,7 @@ module Rails
|
||||||
|
|
||||||
# Eager loads the application code.
|
# Eager loads the application code.
|
||||||
def eager_load!
|
def eager_load!
|
||||||
if Rails.autoloaders.zeitwerk_enabled?
|
Rails.autoloaders.each(&:eager_load)
|
||||||
Rails.autoloaders.each(&:eager_load)
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -9,28 +9,22 @@ module Rails
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def main
|
def main
|
||||||
if zeitwerk_enabled?
|
@main ||= Zeitwerk::Loader.new.tap do |loader|
|
||||||
@main ||= Zeitwerk::Loader.new.tap do |loader|
|
loader.tag = "rails.main"
|
||||||
loader.tag = "rails.main"
|
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
||||||
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def once
|
def once
|
||||||
if zeitwerk_enabled?
|
@once ||= Zeitwerk::Loader.new.tap do |loader|
|
||||||
@once ||= Zeitwerk::Loader.new.tap do |loader|
|
loader.tag = "rails.once"
|
||||||
loader.tag = "rails.once"
|
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
||||||
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def each
|
def each
|
||||||
if zeitwerk_enabled?
|
yield main
|
||||||
yield main
|
yield once
|
||||||
yield once
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def logger=(logger)
|
def logger=(logger)
|
||||||
|
|
|
@ -482,17 +482,8 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def eager_load!
|
def eager_load!
|
||||||
# Already done by Zeitwerk::Loader.eager_load_all. We need this guard to
|
# Already done by Zeitwerk::Loader.eager_load_all. By now, we leave the
|
||||||
# easily provide a compatible API for both zeitwerk and classic modes.
|
# method as a no-op for backwards compatibility.
|
||||||
return if Rails.autoloaders.zeitwerk_enabled?
|
|
||||||
|
|
||||||
config.eager_load_paths.each do |load_path|
|
|
||||||
# Starts after load_path plus a slash, ends before ".rb".
|
|
||||||
relname_range = (load_path.to_s.length + 1)...-3
|
|
||||||
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
|
||||||
require_dependency file[relname_range]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def railties
|
def railties
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
ensure_zeitwerk_mode = ->() do
|
|
||||||
unless Rails.autoloaders.zeitwerk_enabled?
|
|
||||||
abort "Please, enable :zeitwerk mode in config/application.rb and try again."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
eager_load = ->() do
|
eager_load = ->() do
|
||||||
puts "Hold on, I am eager loading the application."
|
puts "Hold on, I am eager loading the application."
|
||||||
Zeitwerk::Loader.eager_load_all
|
Zeitwerk::Loader.eager_load_all
|
||||||
|
|
Loading…
Reference in New Issue