Sha256: fb7feef3c9a8632ffeb66efdbf3fbd63825226d2d065e989e7ddf6405b131dac

Contents?: true

Size: 941 Bytes

Versions: 22

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

module Anyway
  using RubyNext

  module Rails
    module Loaders
      class Secrets < Anyway::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/anyway_config/issues/14
            next if ::Rails.application.initialized?
            ::Rails.application.remove_instance_variable(:@secrets)
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
anyway_config-2.6.4 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.6.3 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.6.2 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.6.1 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.6.0 lib/anyway/rails/loaders/secrets.rb
runger_config-2.7.0 lib/anyway/rails/loaders/secrets.rb
runger_config-2.6.1 lib/anyway/rails/loaders/secrets.rb
runger_config-2.6.0 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.5.4 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.5.3 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.5.2 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.5.1 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.5.0 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.4.2 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.4.1 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.4.0 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.3.1 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.3.0 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.2.3 lib/anyway/rails/loaders/secrets.rb
anyway_config-2.2.2 lib/anyway/rails/loaders/secrets.rb