summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/upcase.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/functions/upcase.rb')
-rw-r--r--lib/puppet/parser/functions/upcase.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index 4302b29..44b3bcd 100644
--- a/lib/puppet/parser/functions/upcase.rb
+++ b/lib/puppet/parser/functions/upcase.rb
@@ -12,23 +12,28 @@ Converts a string or an array of strings to uppercase.
Will return:
- ASDF
- EOS
+ ABCD
+ EOS
) do |arguments|
raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ "given (#{arguments.size} for 1)") if arguments.size != 1
value = arguments[0]
- unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'upcase(): Requires either ' +
- 'array or string to work with')
+ unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase)
+ raise(Puppet::ParseError, 'upcase(): Requires an ' +
+ 'array, hash or object that responds to upcase in order to work')
end
if value.is_a?(Array)
# Numbers in Puppet are often string-encoded which is troublesome ...
- result = value.collect { |i| i.is_a?(String) ? i.upcase : i }
+ result = value.collect { |i| function_upcase([i]) }
+ elsif value.is_a?(Hash)
+ result = {}
+ value.each_pair do |k, v|
+ result[function_upcase([k])] = function_upcase([v])
+ end
else
result = value.upcase
end