Puppet Function: check_array_of_hash

Defined in:
lib/puppet/parser/functions/check_array_of_hash.rb
Function type:
Ruby 3.x API

Overview

check_array_of_hash()Any

Check input String is a valid Array of Hash in JSON style

Returns:

  • (Any)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/parser/functions/check_array_of_hash.rb', line 12

newfunction(:check_array_of_hash, :arity =>1, :type => :rvalue, :doc => "Check
 input String is a valid Array of Hash in JSON style") do |arg|
  if arg[0].class == String
    begin
      list = JSON.load(arg[0].gsub("'","\""))
    rescue JSON::ParserError
      raise Puppet::ParseError, "Syntax error: #{arg[0]} is invalid"
    else
      return arg[0] if array_of_hash?(list)
    end
  else
    raise Puppet::ParseError, "Syntax error: #{arg[0]} is not a String"
  end
  return ''
end