Module: Puppet::Coercion Private

Defined in:
lib/puppet/coercion.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Various methods used to coerce values into a canonical form.

Class Method Summary collapse

Class Method Details

.boolean(value) ⇒ Boolean

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.

Try to coerce various input values into boolean true/false

Only a very limited subset of values are allowed. This method does not try to provide a generic “truthiness” system.

Parameters:

  • value (Boolean, Symbol, String)

Returns:

  • (Boolean)

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/coercion.rb', line 14

def self.boolean(value)
  # downcase strings
  if value.respond_to? :downcase
    value = value.downcase
  end

  case value
  when true, :true, 'true', :yes, 'yes'
    true
  when false, :false, 'false', :no, 'no'
    false
  else
    fail('expected a boolean value')
  end
end

.boolean_valuesArray

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.

Return the list of acceptable boolean values.

This is limited to lower-case, even though boolean() is case-insensitive.

Returns:

  • (Array)

Raises:



37
38
39
# File 'lib/puppet/coercion.rb', line 37

def self.boolean_values
  ['true', 'false', 'yes', 'no']
end