Class: EnvLoader::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/env_loader/configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file: nil, config_content: nil, config_subtree_key: nil) ⇒ Configurator

Returns a new instance of Configurator.



8
9
10
11
12
13
14
# File 'lib/env_loader/configurator.rb', line 8

def initialize(config_file: nil, config_content: nil, config_subtree_key: nil)
  if config_file
    @raw_config = config_from_file(config_file, config_subtree_key)
  elsif config_content
    @raw_config = config_from_content(config_content, config_subtree_key)
  end
end

Instance Attribute Details

#raw_configObject (readonly)

Returns the value of attribute raw_config.



6
7
8
# File 'lib/env_loader/configurator.rb', line 6

def raw_config
  @raw_config
end

Instance Method Details

#configObject



16
17
18
19
20
21
22
# File 'lib/env_loader/configurator.rb', line 16

def config
  raw_config.each_with_object({}) do |hash, new_hash|
    key, value = hash
    value = value.is_a?(Hash) ? value.to_json : value.to_s unless value.nil?
    new_hash[key.upcase] = value
  end
end

#expose_values_as_environment_variablesObject



24
25
26
# File 'lib/env_loader/configurator.rb', line 24

def expose_values_as_environment_variables
  config.each { |key, value| ENV[key] = value }
end