The Zeitwerk integration in Rails 6 has several parts.
-
First, we define a new configuration point
Rails.configuration.autoloaderhere:https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb
and also set it to
:zeitwerkin the 6.0 defaults. -
Then, we define
Rails.autoloadersherehttps://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
Zeitwerkconstant 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.