Last change
on this file since 30903 was 30903, checked in by davidb, 7 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
787 bytes
|
Line | |
---|
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
|
---|
Note:
See
TracBrowser
for help on using the repository browser.