Sha256: 613157764a2d2c6fa9ef616c481bdcdd829e1cc1d047b05615f389cc190bef95

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Dry
  module System
    module ProviderSources
      module Settings
        # @api private
        class Loader
          # @api private
          attr_reader :store

          # @api private
          def initialize(root:, env:, store: ENV)
            @store = store
            load_dotenv(root, env.to_sym)
          end

          # @api private
          def [](key)
            store[key]
          end

          private

          def load_dotenv(root, env)
            require "dotenv"
            Dotenv.load(*dotenv_files(root, env)) if defined?(Dotenv)
          rescue LoadError
            # Do nothing if dotenv is unavailable
          end

          def dotenv_files(root, env)
            [
              File.join(root, ".env.#{env}.local"),
              (File.join(root, ".env.local") unless env == :test),
              File.join(root, ".env.#{env}"),
              File.join(root, ".env")
            ].compact
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-system-1.1.1 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.1.0 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.1.0.beta2 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.1.0.beta1 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.0.1 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.0.0 lib/dry/system/provider_sources/settings/loader.rb
dry-system-1.0.0.rc1 lib/dry/system/provider_sources/settings/loader.rb