Class: Puppet::Settings::TTLSetting
- Inherits:
-
BaseSetting
- Object
- BaseSetting
- Puppet::Settings::TTLSetting
- Defined in:
- lib/puppet/settings/ttl_setting.rb
Overview
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.
Constant Summary collapse
- UNITMAP =
How we convert from various units to seconds.
{ # 365 days isn't technically a year, but is sufficient for most purposes "y" => 365 * 24 * 60 * 60, "d" => 24 * 60 * 60, "h" => 60 * 60, "m" => 60, "s" => 1 }
- FORMAT =
A regex describing valid formats with groups for capturing the value and units
/^(\d+)(y|d|h|m|s)?$/
Instance Attribute Summary
Attributes inherited from BaseSetting
#call_hook, #default, #deprecated, #desc, #name, #section, #short
Class Method Summary collapse
-
.munge(value, param_name) ⇒ Object
Convert the value to Numeric, parsing numeric string with units if necessary.
Instance Method Summary collapse
-
#munge(value) ⇒ Object
Convert the value to Numeric, parsing numeric string with units if necessary.
- #type ⇒ Object
Methods inherited from BaseSetting
#allowed_on_commandline?, available_call_hook_values, #call_hook_on_define?, #call_hook_on_initialize?, #completely_deprecated?, #deprecated?, #getopt_args, #has_hook?, #hook=, #initialize, #inspect, #iscreated, #iscreated?, #optparse_args, #set_meta, #to_config, #value
Constructor Details
This class inherits a constructor from Puppet::Settings::BaseSetting
Class Method Details
.munge(value, param_name) ⇒ Object
Convert the value to Numeric, parsing numeric string with units if necessary.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet/settings/ttl_setting.rb', line 29 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} - did you mean 'unlimited'?") % { value: value.inspect } end value when value == 'unlimited' Float::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}' for parameter: %{param_name}") % { value: value.inspect, param_name: param_name } end end |
Instance Method Details
#munge(value) ⇒ Object
Convert the value to Numeric, parsing numeric string with units if necessary.
24 25 26 |
# File 'lib/puppet/settings/ttl_setting.rb', line 24 def munge(value) self.class.munge(value, @name) end |
#type ⇒ Object
19 20 21 |
# File 'lib/puppet/settings/ttl_setting.rb', line 19 def type :ttl end |