Puppet Function: simplib::params2hash

Defined in:
lib/puppet/functions/simplib/params2hash.rb
Function type:
Ruby 4.x API

Overview

simplib::params2hash(Optional[Array[String[1]]] $prune)Hash

Returns a Hash of the parameters of the calling resource

This is meant to get the parameters of classes and defined types. The behavior when calling from other contexts is undefined

Parameters:

  • prune (Optional[Array[String[1]]])

    Parameters that you wish to exclude from the output

Returns:

  • (Hash)

    All in-scope parameters



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/functions/simplib/params2hash.rb', line 5

Puppet::Functions.create_function(:'simplib::params2hash', Puppet::Functions::InternalFunction) do

  # @param prune
  #   Parameters that you wish to exclude from the output
  #
  # @return [Hash]
  #   All in-scope parameters
  dispatch :params2hash do
    scope_param()
    optional_param 'Array[String[1]]', :prune
  end

  def params2hash(scope, prune=[])
    param_hash = scope.resource.to_hash

    prune << :name if (scope.resource.type == 'Class')

    prune.each do |to_prune|
      next if to_prune.nil?
      param_hash.delete(to_prune.to_sym)
    end

    return param_hash
  end
end