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
- UNITMAP
How we convert from various units to seconds.
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 34 def self.munge(value, param_name) 35 case 36 when value.is_a?(Numeric) 37 if value < 0 38 raise Puppet::Settings::ValidationError, _("Invalid negative 'time to live' %{value} - did you mean 'unlimited'?") % { value: value.inspect } 39 end 40 value 41 42 when value == 'unlimited' 43 Float::INFINITY 44 45 when (value.is_a?(String) and value =~ FORMAT) 46 $1.to_i * UNITMAP[$2 || 's'] 47 else 48 raise Puppet::Settings::ValidationError, _("Invalid 'time to live' format '%{value}' for parameter: %{param_name}") % { value: value.inspect, param_name: param_name } 49 end 50 end
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 24 def munge(value) 25 self.class.munge(value, @name) 26 end
print(value)
click to toggle source
# File lib/puppet/settings/ttl_setting.rb 28 def print(value) 29 val = munge(value) 30 val == Float::INFINITY ? 'unlimited' : val 31 end
type()
click to toggle source
# File lib/puppet/settings/ttl_setting.rb 19 def type 20 :ttl 21 end