Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
727 bytes
|
Rev | Line | |
---|
[30903] | 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.