summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
authorMorgan Haskel <morgan@puppetlabs.com>2015-02-25 16:58:39 -0800
committerMorgan Haskel <morgan@puppetlabs.com>2015-02-25 16:58:39 -0800
commit1ccc4f5e0e77640a2ee3c673ece773cbd17e4981 (patch)
tree80734f517b7366c0eb22089384c0a727bccab944 /lib/puppet/parser/functions
parent3da8d17390832daa7036df06976c442c4f2c7b5d (diff)
parent7021b1f55cdc320c7eb389cd91f6be294629669b (diff)
downloadpuppet-stdlib-1ccc4f5e0e77640a2ee3c673ece773cbd17e4981.tar.gz
puppet-stdlib-1ccc4f5e0e77640a2ee3c673ece773cbd17e4981.tar.bz2
Merge pull request #417 from cyberious/UpcaseHash
Add Hash to upcase
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/upcase.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index 4302b29..22eae3a 100644
--- a/lib/puppet/parser/functions/upcase.rb
+++ b/lib/puppet/parser/functions/upcase.rb
@@ -13,22 +13,27 @@ Converts a string or an array of strings to uppercase.
Will return:
ASDF
- EOS
+ 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?(String) || value.is_a?(Hash)
+ raise(Puppet::ParseError, 'upcase(): Requires an ' +
+ 'array, string or hash to work with')
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 }
+ elsif value.is_a?(Hash)
+ result = {}
+ result << value.each_pair do |k, v|
+ return {k.upcase => v.collect! { |p| p.upcase }}
+ end
else
result = value.upcase
end