Module: Rails::Autoloaders

Extended by:
Enumerable
Defined in:
railties/lib/rails/autoloaders.rb

Overview

:nodoc:

Class Method Summary collapse

Methods included from Enumerable

as_json, compact_blank, exclude?, excluding, including, index_by, index_with, many?, pluck, sum, without

Class Method Details

.eachObject



28
29
30
31
32
33
# File 'railties/lib/rails/autoloaders.rb', line 28

def each
  if zeitwerk_enabled?
    yield main
    yield once
  end
end

.log!Object



39
40
41
# File 'railties/lib/rails/autoloaders.rb', line 39

def log!
  each(&:log!)
end

.logger=(logger) ⇒ Object



35
36
37
# File 'railties/lib/rails/autoloaders.rb', line 35

def logger=(logger)
  each { |loader| loader.logger = logger }
end

.mainObject



10
11
12
13
14
15
16
17
# File 'railties/lib/rails/autoloaders.rb', line 10

def main
  if zeitwerk_enabled?
    @main ||= Zeitwerk::Loader.new.tap do |loader|
      loader.tag = "rails.main"
      loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
    end
  end
end

.onceObject



19
20
21
22
23
24
25
26
# File 'railties/lib/rails/autoloaders.rb', line 19

def once
  if zeitwerk_enabled?
    @once ||= Zeitwerk::Loader.new.tap do |loader|
      loader.tag = "rails.once"
      loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
    end
  end
end

.zeitwerk_enabled?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'railties/lib/rails/autoloaders.rb', line 43

def zeitwerk_enabled?
  Rails.configuration.autoloader == :zeitwerk
end