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