Sha256: 67fecc9b34415b2ba77770d30d531bab310158cf5e6fb1b64bc51fef34567ccf

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

require "dry/core/constants"

module Hanami
  class Settings
    # The default store for {Hanami:Settings}, loading setting values from `ENV`.
    #
    # If your app loads the dotenv gem, then `ENV` will also be populated from various `.env` files when
    # you subclass `Hanami::App`.
    #
    # @since 2.0.0
    # @api private
    class EnvStore
      NO_ARG = Object.new.freeze

      attr_reader :store, :hanami_env

      def initialize(store: ENV, hanami_env: Hanami.env)
        @store = store
        @hanami_env = hanami_env
      end

      def fetch(name, default_value = NO_ARG, &block)
        name = name.to_s.upcase
        args = default_value.eql?(NO_ARG) ? [name] : [name, default_value]

        store.fetch(*args, &block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-2.0.0.beta4 lib/hanami/settings/env_store.rb