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:
665 bytes
|
Line | |
---|
1 | module Puppet::Parser::Functions
|
---|
2 | newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
|
---|
3 | Takes an array as first argument and an optional second argument.
|
---|
4 | Count the number of elements in array that matches second argument.
|
---|
5 | If called with only an array it counts the number of elements that are not nil/undef.
|
---|
6 | EOS
|
---|
7 | ) do |args|
|
---|
8 |
|
---|
9 | if (args.size > 2) then
|
---|
10 | raise(ArgumentError, "count(): Wrong number of arguments "+
|
---|
11 | "given #{args.size} for 1 or 2.")
|
---|
12 | end
|
---|
13 |
|
---|
14 | collection, item = args
|
---|
15 |
|
---|
16 | if item then
|
---|
17 | collection.count item
|
---|
18 | else
|
---|
19 | collection.count { |obj| obj != nil && obj != :undef && obj != '' }
|
---|
20 | end
|
---|
21 | end
|
---|
22 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.