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



13
14
15
16
# File 'lib/eac_config/envvars_node/entry.rb', line 13

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



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

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

  string
end

.to_value(object) ⇒ Object



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

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)


35
36
37
# File 'lib/eac_config/envvars_node/entry.rb', line 35

def found?
  ENV.key?(envvar_name)
end

#valueObject



39
40
41
# File 'lib/eac_config/envvars_node/entry.rb', line 39

def value
  self.class.from_value(ENV[envvar_name])
end

#value=(a_value) ⇒ Object



43
44
45
# File 'lib/eac_config/envvars_node/entry.rb', line 43

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