Sha256: 0febcbb73f4c79d405897239bfc01e82c118a1fc83701c27412995568084fb4c

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

# This module is used to detect a Rails application and activate the corresponding plugins
# when Anyway Config is loaded before Rails (e.g., in config/puma.rb).
module Anyway
  module Rails
    using RubyNext

    class << self
      attr_reader :tracer, :name_method
      attr_accessor :disable_postponed_load_warning

      private

      def tracepoint_class_callback(event)
        # Ignore singletons
        return if event.self.singleton_class?

        # We wait till `rails/application/configuration.rb` has been loaded, since we rely on it
        # See https://github.com/palkan/anyway_config/issues/134
        return unless name_method.bind_call(event.self) == "Rails::Application::Configuration"

        tracer.disable

        unless disable_postponed_load_warning
          warn "Anyway Config was loaded before Rails. Activating Anyway Config Rails plugins now.\n" \
                "NOTE: Already loaded configs were provisioned without Rails-specific sources."
        end

        require "anyway/rails"
      end
    end

    @tracer = TracePoint.new(:end, &method(:tracepoint_class_callback))
    @tracer.enable
    # Use `Module#name` instead of `self.name` to handle overwritten `name` method
    @name_method = Module.instance_method(:name)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
anyway_config-2.5.1 lib/anyway/rails/autoload.rb