Sha256: d4d2cd25a9c7f24a245d84f5460089d778d0303f422efc1a2a65acd7aa0a60be

Contents?: true

Size: 596 Bytes

Versions: 5

Compression:

Stored size: 596 Bytes

Contents

require "easy-settings/path_source"
require "active_support/core_ext/object"

class EasySettings::EnvSource < EasySettings::PathSource
  attr_reader :prefix

  def initialize(prefix, separator: "__", converter: :downcase, parse_values: true)
    @prefix = prefix
    super(nil, separator: separator, converter: converter, parse_values: parse_values)
  end

  def load
    {}.tap do |data|
      ENV.each do |variable, value|
        keys = variable.to_s.split(separator)
        next if prefix.present? && keys.shift != prefix

        assign_value(data, keys, value)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy-settings-2.0.2 lib/easy-settings/env_source.rb
easy-settings-2.0.1 lib/easy-settings/env_source.rb
easy-settings-2.0.0 lib/easy-settings/env_source.rb
easy-settings-1.4.0 lib/easy-settings/env_source.rb
easy-settings-1.3.1 lib/easy-settings/env_source.rb