Class: Puppet::Settings::ChainedValues

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/settings.rb

Overview

Lookup configuration setting value through a chain of different value sources.

Constant Summary collapse

ENVIRONMENT_SETTING =
"environment".freeze
ENVIRONMENT_INTERPOLATION_ALLOWED =
['config_version'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(mode, environment, value_sets, defaults) ⇒ ChainedValues

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChainedValues.

See Also:

  • Puppet::Settings.values

1374
1375
1376
1377
1378
1379
# File 'lib/puppet/settings.rb', line 1374

def initialize(mode, environment, value_sets, defaults)
  @mode = mode
  @environment = environment
  @value_sets = value_sets
  @defaults = defaults
end

Instance Method Details

#interpolate(name) ⇒ Object

Lookup the interpolated value. All instances of `$name` in the value will be replaced by performing a lookup of `name` and substituting the text for `$name` in the original value. This interpolation is only performed if the looked up value is a String.

Parameters:

  • name (Symbol)

    The configuration setting name to look up

Returns:

  • (Object)

    The configuration setting value or nil if the setting is not known


1408
1409
1410
1411
1412
1413
1414
1415
# File 'lib/puppet/settings.rb', line 1408

def interpolate(name)
  setting = @defaults[name]
  return nil unless setting

  lookup_and_convert(name) do |val|
    setting.munge(val)
  end
end

#lookup(name) ⇒ Object

Lookup the uninterpolated value.

Parameters:

  • name (Symbol)

    The configuration setting name to look up

Returns:

  • (Object)

    The configuration setting value or nil if the setting is not known


1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/puppet/settings.rb', line 1386

def lookup(name)
  set = @value_sets.find do |value_set|
    value_set.include?(name)
  end
  if set
    value = set.lookup(name)
    if !value.nil?
      return value
    end
  end

  @defaults[name].default
end

1417
1418
1419
1420
1421
1422
1423
1424
# File 'lib/puppet/settings.rb', line 1417

def print(name)
  setting = @defaults[name]
  return nil unless setting

  lookup_and_convert(name) do |val|
    setting.print(val)
  end
end