Module: Weft::Autoloading

Defined in:
lib/weft/autoloading.rb

Overview

Zeitwerk-backed autoloading for application code, behind configure_autoloading. Each call builds one Zeitwerk loader over the given paths and eager-loads it immediately — Weft routes from the Registry, which populates via the inherited hook, so the classes must exist before the first request (lazy autoload alone would serve an empty route table).

With reload: true, a per-request Router hook reloads constants, and Zeitwerk's on_unload callback evicts each outgoing class from the registry as it unloads — the push-model complement to Registry#evict, which hand-rolled reloaders call directly.

Class Method Summary collapse

Class Method Details

.loadersObject

Loaders created so far, in creation order. @api private



20
21
22
# File 'lib/weft/autoloading.rb', line 20

def loaders
  @loaders ||= []
end

.setup(paths:, inflections: {}, reload: false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/weft/autoloading.rb', line 24

def setup(paths:, inflections: {}, reload: false)
  paths = Array(paths)
  validate!(paths, inflections)
  require "zeitwerk"

  loader = build_loader(paths, inflections, reload)
  loader.setup
  loader.eager_load
  install_reload_hook(loader) if reload
  loaders << loader
  loader
end