Class: Konfig::Sources::Environment

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

Class Method Summary collapse

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

Class Method Details

.path_to_env_var(path) ⇒ Object



34
35
36
# File 'lib/konfig/sources/environment.rb', line 34

def path_to_env_var(path)
  path.map { |p| p.to_s.upcase }.join('_')
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 = self.class.path_to_env_var(path)
  raise ValueNotPresentError unless @env.key?(key)

  value = @env[key]

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