Puppet Function: yum::bool2num_hash_recursive

Defined in:
functions/bool2num_hash_recursive.pp
Function type:
Puppet Language

Overview

yum::bool2num_hash_recursive(Hash $arg)Hash

This functions converts the Boolean values of a Hash to Integers, either ‘0’ or ‘1’. It does this recursively, decending as far as the language implemenation will allow. Note that Structs and Arrays will be ignored, even if they contain Hashes.

Examples:

Usage


Hash $foo = {
  bar => { 'a' => true, 'b' => 'b' },
  baz => false,
  qux => [{ 'c' => true }, { 'd' => false }],
}

yum::bool2num_hash_recursive($foo)

The above would return:

{
  bar => { 'a' => 1, 'b' => 'b' },
  baz => 0,
  qux => [{ 'c' => true }, { 'd' => false }],
}

Parameters:

  • arg (Hash)

    The hash on which to operate

Returns:

  • (Hash)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'functions/bool2num_hash_recursive.pp', line 29

function yum::bool2num_hash_recursive($arg) {
  assert_type(Hash, $arg)
  $arg.map |$key, $value| {
    $return_value = $value ? {
      Boolean => bool2num($value),
      Hash    => yum::bool2num_hash_recursive($value),
      default => $value,
    }
    # see the issue for the strange/asymetrical whitespace
    # https://github.com/kuleuven/puppet-lint-manifest_whitespace-check/issues/8
    Hash({ $key => $return_value })
  }.reduce |$attrs_memo, $kv| {
    $attrs_memo + $kv
  }
}