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:



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

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

  case value
  when true, :true, 'true', :yes, 'yes' # rubocop:disable Lint/BooleanSymbol
    true
  when false, :false, 'false', :no, 'no' # rubocop:disable Lint/BooleanSymbol
    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:



39
40
41
# File 'lib/puppet/coercion.rb', line 39

def self.boolean_values
  %w[true false yes no]
end