]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/has_key.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / has_key.rb
1 module Puppet::Parser::Functions
2
3   newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4     Determine if a hash has a certain key value.
5
6     Example:
7
8         $my_hash = {'key_one' => 'value_one'}
9         if has_key($my_hash, 'key_two') {
10           notice('we will not reach here')
11         }
12         if has_key($my_hash, 'key_one') {
13           notice('this will be printed')
14         }
15
16     ENDHEREDOC
17
18     unless args.length == 2
19       raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
20     end
21     unless args[0].is_a?(Hash)
22       raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
23     end
24     args[0].has_key?(args[1])
25
26   end
27
28 end