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


1212
1213
1214
1215
1216
1217
# File 'lib/puppet/settings.rb', line 1212

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



1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
# File 'lib/puppet/settings.rb', line 1246

def interpolate(name)
  setting = @defaults[name]

  if setting
    val = lookup(name)
    # if we interpolate code, all hell breaks loose.
    if name == :code
      val
    else
      # Convert it if necessary
      begin
        val = convert(val, name)
      rescue InterpolationError => err
        # This happens because we don't have access to the param name when the
        # exception is originally raised, but we want it in the message
        raise InterpolationError, "Error converting value for param '#{name}': #{err}", err.backtrace
      end

      setting.munge(val)
    end
  else
    nil
  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



1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# File 'lib/puppet/settings.rb', line 1224

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