From 7021b1f55cdc320c7eb389cd91f6be294629669b Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 25 Feb 2015 11:39:27 -0800 Subject: Add Hash to upcase --- lib/puppet/parser/functions/upcase.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser/functions/upcase.rb') 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 -- cgit v1.2.3 From 419f51bdd9d2aa35a94fbabbfaaf1cbfd81920f4 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Thu, 26 Feb 2015 10:13:28 -0800 Subject: Fix issue with Ruby 1.8.7 which did not allow for the return in an each_pair of the hash --- lib/puppet/parser/functions/upcase.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions/upcase.rb') diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 22eae3a..2b05db4 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -31,8 +31,8 @@ Will return: 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 }} + value.each_pair do |k, v| + result.merge!({k.upcase => v.collect! { |p| p.upcase }}) end else result = value.upcase -- cgit v1.2.3 From 85e81f9bdf9d482338c504ff3c658993a24978a0 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 27 Feb 2015 17:40:32 -0800 Subject: Loosen the restrictions of upcase and allow for recursion of the objects and only worry if the object responds to upcase --- lib/puppet/parser/functions/upcase.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser/functions/upcase.rb') diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 2b05db4..0226a88 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -17,22 +17,22 @@ Will return: ) 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) || value.is_a?(Hash) + unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase) raise(Puppet::ParseError, 'upcase(): Requires an ' + - 'array, string or hash to work with') + '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.merge!({k.upcase => v.collect! { |p| p.upcase }}) + result[function_upcase([k])] = function_upcase([v]) end else result = value.upcase -- cgit v1.2.3 From 939aceffad5c9eafbab336e4e5e7477a97154e41 Mon Sep 17 00:00:00 2001 From: Dan Offord Date: Mon, 20 Jul 2015 17:55:52 +0100 Subject: Fix documentation error in upcase The documentation example shows an incorrect response when using the function, this PR corrects the example to agree with what the function actually does. --- lib/puppet/parser/functions/upcase.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/upcase.rb') diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 0226a88..44b3bcd 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -12,7 +12,7 @@ Converts a string or an array of strings to uppercase. Will return: - ASDF + ABCD EOS ) do |arguments| -- cgit v1.2.3