Puppet Function: :'wmflib::dump_params'

Defined in:
modules/wmflib/lib/puppet/functions/wmflib/dump_params.rb
Function type:
Ruby 4.x API

Overview

:'wmflib::dump_params'(Optional[Array[String[1]]] $filter_keys)Any

Examples:

file { '/etc/foo/config.yaml':
  ensure => file,
  content => wmflib::dump_params.to_yaml
}

Parameters:

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

    an optional parameters of keys to filter out

Returns:

  • (Any)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'modules/wmflib/lib/puppet/functions/wmflib/dump_params.rb', line 8

Puppet::Functions.create_function(:'wmflib::dump_params', Puppet::Functions::InternalFunction) do
  # @param filter_keys an optional parameters of keys to filter out
  dispatch :dump_params do
    scope_param
    optional_param 'Array[String[1]]', :filter_keys
  end

  def dump_params(scope, filter_keys = ['name'])
    scope.resource.to_hash.collect{|k, v| [k.to_s, v]}.to_h.reject {|k, _v| filter_keys.include?(k) }
    # TODO: when ruby 2.5 everywhere
    # scope.resource.to_hash.transform_keys(&:to_s).reject {|k, _v| filter_keys.include?(k) }
  end
end