diff modules/stdlib/lib/puppet/parser/functions/size.rb @ 272:c42fb28cff86

Update to a newer Python module This also pulls in an EPEL module (which we don't use) and a newer stdlib version.
author IBBoard <dev@ibboard.co.uk>
date Fri, 03 Jan 2020 19:56:04 +0000
parents 956e484adc12
children d9352a684e62
line wrap: on
line diff
--- a/modules/stdlib/lib/puppet/parser/functions/size.rb	Tue Dec 31 13:49:38 2019 +0000
+++ b/modules/stdlib/lib/puppet/parser/functions/size.rb	Fri Jan 03 19:56:04 2020 +0000
@@ -1,20 +1,18 @@
 #
 # size.rb
 #
-
-# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
+module Puppet::Parser::Functions
+  newfunction(:size, :type => :rvalue, :doc => <<-DOC
+    Returns the number of elements in a string, an array or a hash
+  DOC
+             ) do |arguments|
 
-module Puppet::Parser::Functions
-  newfunction(:size, :type => :rvalue, :doc => <<-EOS
-Returns the number of elements in a string or array.
-    EOS
-  ) do |arguments|
-
-    raise(Puppet::ParseError, "size(): Wrong number of arguments " +
-      "given (#{arguments.size} for 1)") if arguments.size < 1
+    raise(Puppet::ParseError, "size(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
 
     item = arguments[0]
 
+    function_deprecation([:size, 'This method is going to be deprecated, please use the stdlib length function.'])
+
     if item.is_a?(String)
 
       begin
@@ -28,14 +26,12 @@
         #
         Float(item)
 
-        raise(Puppet::ParseError, 'size(): Requires either ' +
-          'string or array to work with')
-
+        raise(Puppet::ParseError, 'size(): Requires either string, array or hash to work with')
       rescue ArgumentError
         result = item.size
       end
 
-    elsif item.is_a?(Array)
+    elsif item.is_a?(Array) || item.is_a?(Hash)
       result = item.size
     else
       raise(Puppet::ParseError, 'size(): Unknown type given')