Class: EacConfig::EnvvarsNode::Entry

Inherits:
NodeEntry
  • Object
show all
Defined in:
lib/eac_config/envvars_node/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeEntry

#secret_value, #to_s

Class Method Details

.entry_path_to_envvar_name(path) ⇒ Object



11
12
13
14
# File 'lib/eac_config/envvars_node/entry.rb', line 11

def entry_path_to_envvar_name(path)
  ::EacConfig::EntryPath.assert(path).parts.join('_').gsub(/[^a-z0-9_]/i, '')
    .gsub(/\A_+/, '').gsub(/_+\z/, '').gsub(/_{2,}/, '_').upcase
end

.from_value(string) ⇒ Object



16
17
18
19
20
21
# File 'lib/eac_config/envvars_node/entry.rb', line 16

def from_value(string)
  return nil if string.nil?
  return ::EacRubyUtils::Yaml.load(string) if string.start_with?('---')

  string
end

.to_value(object) ⇒ Object



23
24
25
26
27
28
# File 'lib/eac_config/envvars_node/entry.rb', line 23

def to_value(object)
  return nil if object.nil?
  return object if object.is_a?(String)

  ::EacRubyUtils::Yaml.dump(object)
end

Instance Method Details

#found?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/eac_config/envvars_node/entry.rb', line 33

def found?
  ENV.key?(envvar_name)
end

#valueObject



37
38
39
# File 'lib/eac_config/envvars_node/entry.rb', line 37

def value
  self.class.from_value(ENV.fetch(envvar_name, nil))
end

#value=(a_value) ⇒ Object



41
42
43
# File 'lib/eac_config/envvars_node/entry.rb', line 41

def value=(a_value)
  ENV[envvar_name] = self.class.to_value(a_value)
end