5 # TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
6 # TODO(Krzysztof Wilczynski): Support for strings and hashes too ...
8 module Puppet::Parser::Functions
9 newfunction(:member, :type => :rvalue, :doc => <<-EOS
10 This function determines if a variable is a member of an array.
11 The variable can be a string, fixnum, or array.
15 member(['a','b'], 'b')
19 member(['a', 'b', 'c'], ['a', 'b'])
23 member(['a','b'], 'c')
27 member(['a', 'b', 'c'], ['d', 'b'])
33 raise(Puppet::ParseError, "member(): Wrong number of arguments " +
34 "given (#{arguments.size} for 2)") if arguments.size < 2
38 unless array.is_a?(Array)
39 raise(Puppet::ParseError, 'member(): Requires array to work with')
42 unless arguments[1].is_a? String or arguments[1].is_a? Fixnum or arguments[1].is_a? Array
43 raise(Puppet::ParseError, 'member(): Item to search for must be a string, fixnum, or array')
46 if arguments[1].is_a? String or arguments[1].is_a? Fixnum
47 item = Array(arguments[1])
53 raise(Puppet::ParseError, 'member(): You must provide item ' +
54 'to search for within array given') if item.respond_to?('empty?') && item.empty?
56 result = (item - array).empty?
62 # vim: set ts=2 sw=2 et :