try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / lib / puppet / parser / functions / check_array_of_hash.rb
1 require 'json'
2
3 def array_of_hash?(list)
4   return false unless !list.empty? && list.class == Array
5   list.each do |e|
6     return false unless e.class == Hash
7   end
8   true
9 end
10
11 module Puppet::Parser::Functions
12   newfunction(:check_array_of_hash, :arity =>1, :type => :rvalue, :doc => "Check
13  input String is a valid Array of Hash in JSON style") do |arg|
14     if arg[0].class == String
15       begin
16         list = JSON.load(arg[0].gsub("'","\""))
17       rescue JSON::ParserError
18         raise Puppet::ParseError, "Syntax error: #{arg[0]} is invalid"
19       else
20         return arg[0] if array_of_hash?(list)
21       end
22     else
23       raise Puppet::ParseError, "Syntax error: #{arg[0]} is not a String"
24     end
25     return ''
26   end
27 end