Last change
on this file since 30960 was 30960, checked in by davidb, 7 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
727 bytes
|
Line | |
---|
1 | module Puppet::Parser::Functions
|
---|
2 | newfunction(:delete_values, :type => :rvalue, :doc => <<-EOS
|
---|
3 | Deletes all instances of a given value from a hash.
|
---|
4 |
|
---|
5 | *Examples:*
|
---|
6 |
|
---|
7 | delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')
|
---|
8 |
|
---|
9 | Would return: {'a'=>'A','c'=>'C','B'=>'D'}
|
---|
10 |
|
---|
11 | EOS
|
---|
12 | ) do |arguments|
|
---|
13 |
|
---|
14 | raise(Puppet::ParseError,
|
---|
15 | "delete_values(): Wrong number of arguments given " +
|
---|
16 | "(#{arguments.size} of 2)") if arguments.size != 2
|
---|
17 |
|
---|
18 | hash, item = arguments
|
---|
19 |
|
---|
20 | if not hash.is_a?(Hash)
|
---|
21 | raise(TypeError, "delete_values(): First argument must be a Hash. " + \
|
---|
22 | "Given an argument of class #{hash.class}.")
|
---|
23 | end
|
---|
24 | hash.dup.delete_if { |key, val| item == val }
|
---|
25 | end
|
---|
26 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.