Puppet Function: mysql::strip_hash

Defined in:
lib/puppet/functions/mysql/strip_hash.rb
Function type:
Ruby 4.x API

Summary

When given a hash this function strips out all blank entries.

Overview

mysql::strip_hash(Hash $hash)Hash

Parameters:

  • hash (Hash)

    Hash to be stripped

Returns:

  • (Hash)

    hash The given hash with all blank entries removed



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/functions/mysql/strip_hash.rb', line 6

Puppet::Functions.create_function(:'mysql::strip_hash') do
  # @param hash
  #   Hash to be stripped
  #
  # @return hash
  #   The given hash with all blank entries removed
  #
  dispatch :strip_hash do
    required_param 'Hash', :hash
    return_type 'Hash'
  end

  def strip_hash(hash)
    # Filter out all the top level blanks.
    hash.reject { |_k, v| v == '' }.each do |_k, v|
      v.reject! { |_ki, vi| vi == '' } if v.is_a?(Hash)
    end
  end
end