class Puppet::Settings::TTLSetting

A setting that represents a span of time to live, and evaluates to Numeric seconds to live where 0 means shortest possible time to live, a positive numeric value means time to live in seconds, and the symbolic entry ‘unlimited’ is an infinite amount of time.

Constants

FORMAT

A regex describing valid formats with groups for capturing the value and units

INFINITY
UNITMAP

How we convert from various units to seconds.

Public Instance Methods

munge(value) click to toggle source

Convert the value to Numeric, parsing numeric string with units if necessary.

# File lib/puppet/settings/ttl_setting.rb, line 26
def munge(value)
  self.class.munge(value, @name)
end
type() click to toggle source
# File lib/puppet/settings/ttl_setting.rb, line 21
def type
  :ttl
end

Public Class Methods

munge(value, param_name) click to toggle source

Convert the value to Numeric, parsing numeric string with units if necessary.

# File lib/puppet/settings/ttl_setting.rb, line 31
def self.munge(value, param_name)
  case
  when value.is_a?(Numeric)
    if value < 0
      raise Puppet::Settings::ValidationError, "Invalid negative 'time to live' #{value.inspect} - did you mean 'unlimited'?"
    end
    value

  when value == 'unlimited'
    INFINITY

  when (value.is_a?(String) and value =~ FORMAT)
    $1.to_i * UNITMAP[$2 || 's']
  else
    raise Puppet::Settings::ValidationError, "Invalid 'time to live' format '#{value.inspect}' for parameter: #{param_name}"
  end
end