Sha256: 35346c28c99c4df9f1ea5977c34a589be915ae93b89f66447fa931038a6f7990

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

module Runger
  module Rails
    module Loaders
      class Secrets < Runger::Loaders::Base
        def call(name:, **_options)
          return {} unless ::Rails.application.respond_to?(:secrets)

          # Create a new hash cause secrets are mutable!
          config = {}

          trace!(:secrets) do
            secrets.public_send(name)
          end.then do |secrets|
            Utils.deep_merge!(config, secrets) if secrets
          end

          config
        end

        private

        def secrets
          @secrets ||= ::Rails.application.secrets.tap do |_|
            # Reset secrets state if the app hasn't been initialized
            # See https://github.com/palkan/runger_config/issues/14
            next if ::Rails.application.initialized?
            ::Rails.application.remove_instance_variable(:@secrets)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
runger_config-4.0.0 lib/runger/rails/loaders/secrets.rb