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, #settings_root

Instance Method Summary collapse

Methods inherited from PathSource

#assign_value

Constructor Details

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

Returns a new instance of EnvSource.



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

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.



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

def prefix
  @prefix
end

Instance Method Details

#loadObject



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

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