Class: EasySettings::EnvSource

Inherits:
PathSource show all
Defined in:
lib/easy-settings/env_source.rb

Instance Attribute Summary collapse

Attributes inherited from PathSource

#base_path, #converter, #parse_values, #separator

Instance Method Summary collapse

Methods inherited from PathSource

#assign_value

Constructor Details

#initialize(prefix, separator: "__", converter: :downcase, parse_values: true) ⇒ EnvSource



6
7
8
9
# File 'lib/easy-settings/env_source.rb', line 6

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

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



4
5
6
# File 'lib/easy-settings/env_source.rb', line 4

def prefix
  @prefix
end

Instance Method Details

#loadObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/easy-settings/env_source.rb', line 11

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