2019-02-17 03:11:53 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-08 11:47:24 -05:00
|
|
|
require "active_support/dependencies/zeitwerk_integration"
|
|
|
|
|
2019-02-14 18:12:57 -05:00
|
|
|
module Rails
|
|
|
|
module Autoloaders # :nodoc:
|
|
|
|
class << self
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
def main
|
|
|
|
if zeitwerk_enabled?
|
2019-03-08 10:48:52 -05:00
|
|
|
@main ||= Zeitwerk::Loader.new.tap do |loader|
|
|
|
|
loader.tag = "rails.main"
|
|
|
|
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
|
|
|
end
|
2019-02-14 18:12:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def once
|
|
|
|
if zeitwerk_enabled?
|
2019-03-08 10:48:52 -05:00
|
|
|
@once ||= Zeitwerk::Loader.new.tap do |loader|
|
|
|
|
loader.tag = "rails.once"
|
|
|
|
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
|
|
|
end
|
2019-02-14 18:12:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
if zeitwerk_enabled?
|
|
|
|
yield main
|
|
|
|
yield once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-21 04:26:36 -05:00
|
|
|
def logger=(logger)
|
2019-02-21 17:35:09 -05:00
|
|
|
each { |loader| loader.logger = logger }
|
2019-02-21 04:26:36 -05:00
|
|
|
end
|
|
|
|
|
2019-08-13 12:14:50 -04:00
|
|
|
def log!
|
|
|
|
each(&:log!)
|
|
|
|
end
|
|
|
|
|
2019-02-14 18:12:57 -05:00
|
|
|
def zeitwerk_enabled?
|
|
|
|
Rails.configuration.autoloader == :zeitwerk
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|