Sha256: 56603fa1e96b3ab931706f5409d9d88ff5b710f5c0d91b975de92bb73ce99d55

Contents?: true

Size: 1016 Bytes

Versions: 2

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

require "active_support/dependencies/zeitwerk_integration"

module Rails
  module Autoloaders # :nodoc:
    class << self
      include Enumerable

      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

      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

      def each
        if zeitwerk_enabled?
          yield main
          yield once
        end
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
railties-6.0.0.rc2 lib/rails/autoloaders.rb
railties-6.0.0.rc1 lib/rails/autoloaders.rb