Class: Contrast::Config::Diagnostics::SourceConfigValue

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/config/diagnostics/source_config_value.rb

Overview

All config values from all sources, stored in a easy to write representation.

Direct Known Subclasses

EffectiveConfigValue

Constant Summary collapse

NULL =
'null'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#canonical_nameString

Returns Name of the config starting form root of yaml config.

Returns:

  • (String)

    Name of the config starting form root of yaml config.



15
16
17
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 15

def canonical_name
  @canonical_name
end

#filenameString?

Returns The filename for the source of the config, if the source was “yaml”.

Returns:

  • (String, nil)

    The filename for the source of the config, if the source was “yaml”.



23
24
25
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 23

def filename
  @filename
end

#keyString

Returns Name of the config.

Returns:

  • (String)

    Name of the config.



17
18
19
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 17

def key
  @key
end

#sourceString

Returns The source for the entry in the config.

Returns:

  • (String)

    The source for the entry in the config.



21
22
23
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 21

def source
  @source
end

#valueString, ...

Returns Value set for the config. Current Effective Value.

Returns:

  • (String, Boolean, array<String>)

    Value set for the config. Current Effective Value



19
20
21
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 19

def value
  @value
end

Instance Method Details

#assign_filename(source) ⇒ Array<String>?

Assigns file name of the config iv viable, Currently supported formats for config file are *.yaml and *.yml. For the config loaded from file the filename is kept as source.

Parameters:

  • source (String)

    name of the source file yaml | yml

Returns:



48
49
50
51
52
53
54
55
56
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 48

def assign_filename source
  Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS.each do |type|
    # We use the source to transfer the file's name from the mapping of the extensions.
    # This is done b/c the user_configuration file has a second field to be filled,
    # and other sources don't. Transfer the source as filename and set the default value
    # for it later when we find the sources.
    instance_variable_set(:@filename, source) if source.include?(".#{ type.downcase }")
  end
end

#to_controlled_hashObject



25
26
27
28
29
30
31
32
33
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 25

def to_controlled_hash
  {
      canonical_name: canonical_name,
      name: key || Contrast::Utils::ObjectShare::EMPTY_STRING,
      value: Contrast::Config::Diagnostics::Tools.value_to_s(value),
      source: source || Contrast::Utils::ObjectShare::EMPTY_STRING,
      filename: filename || Contrast::Utils::ObjectShare::EMPTY_STRING
  }
end

#to_source_hashObject



35
36
37
38
39
40
41
# File 'lib/contrast/config/diagnostics/source_config_value.rb', line 35

def to_source_hash
  {
      canonical_name: canonical_name,
      name: key || Contrast::Utils::ObjectShare::EMPTY_STRING,
      value: Contrast::Config::Diagnostics::Tools.value_to_s(value)
  }
end