The Zeitwerk integration in Rails 6 has several parts.
-
First, we define a new configuration point
Rails.configuration.autoloader
here:https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb
and also set it to
:zeitwerk
in the 6.0 defaults. -
Then, we define
Rails.autoloaders
herehttps://github.com/rails/rails/blob/master/railties/lib/rails/autoloaders.rb
-
When the application is finishing the boot process, Zeitwerk takes over AS::Dependencies depending on the configuration. It happens in the finisher
let_zeitwerk_take_over
:https://github.com/rails/rails/blob/master/railties/lib/rails/application/finisher.rb
-
In the same file above, eager loading delegates to Zeitwerk if the
Zeitwerk
constant is defined, regardless of whether the application itself is using it (because there could be gem dependencies using it). Seeeager_load!
. -
This is the main file, the one in which Zeitwerk is setup:
Everything has been thought in a way that leaves the classic autoloader untouched, to guarantee classic works as always in case you want to opt-out.