summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorYanis Guenane <yguenane@gmail.com>2014-09-15 14:16:52 -0400
committerYanis Guenane <yanis.guenane@enovance.com>2014-11-12 14:40:34 -0500
commitc9f906f80325a12a6509633d87472bd3cbaf0364 (patch)
treeeca4dba4d953c381a2fd3c66eb9916de64b13dd4 /lib/puppet/parser
parent85d7eddc41b04c9a9a7bf1a171dd8d3ab157a88a (diff)
downloadpuppet-stdlib-c9f906f80325a12a6509633d87472bd3cbaf0364.tar.gz
puppet-stdlib-c9f906f80325a12a6509633d87472bd3cbaf0364.tar.bz2
(MODULES-1329) Allow member function to look for array
Currently, the member function allows one to only find if a variable is part of an array. Sometimes it is useful to find if an array is part of a bigger array for validation purpose.
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/functions/member.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb
index 11a1d24..bb19a86 100644
--- a/lib/puppet/parser/functions/member.rb
+++ b/lib/puppet/parser/functions/member.rb
@@ -8,6 +8,7 @@
module Puppet::Parser::Functions
newfunction(:member, :type => :rvalue, :doc => <<-EOS
This function determines if a variable is a member of an array.
+The variable can either be a string or an array.
*Examples:*
@@ -15,9 +16,17 @@ This function determines if a variable is a member of an array.
Would return: true
+ member(['a', 'b', 'c'], ['a', 'b'])
+
+would return: true
+
member(['a','b'], 'c')
Would return: false
+
+ member(['a', 'b', 'c'], ['d', 'b'])
+
+would return: false
EOS
) do |arguments|
@@ -30,13 +39,17 @@ Would return: false
raise(Puppet::ParseError, 'member(): Requires array to work with')
end
- item = arguments[1]
+ if arguments[1].is_a? String
+ item = Array(arguments[1])
+ else
+ item = arguments[1]
+ end
raise(Puppet::ParseError, 'member(): You must provide item ' +
'to search for within array given') if item.respond_to?('empty?') && item.empty?
- result = array.include?(item)
+ result = (item - array).empty?
return result
end