Class: Konfig::Sources::Environment

Inherits:
Abstract
  • Object
show all
Defined in:
lib/konfig/sources/environment.rb

Instance Method Summary collapse

Constructor Details

#initialize(env, array_separator: /\s*,\s*/) ⇒ Environment

Returns a new instance of Environment.



10
11
12
13
14
# File 'lib/konfig/sources/environment.rb', line 10

def initialize(env, array_separator: /\s*,\s*/)
  super()
  @env = env
  @array_separator = array_separator
end

Instance Method Details

#get(path, attribute: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/konfig/sources/environment.rb', line 16

def get(path, attribute: nil)
  key = path.map { |p| p.to_s.upcase }.join('_')
  raise ValueNotPresentError unless @env.key?(key)

  value = @env[key]

  value = handle_array(value) if attribute&.array?
  value
end