X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fsize.rb;h=b503aa09e1f958443cdc6a02faa77df6c928c822;hb=6963202b4b62c2816655ac9532521b018fdf83bd;hp=cc207e3fadc40fc10477eb351fcfd1d4ac775704;hpb=a69999e580f8b3abd12446c2d6ad59e517651813;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/size.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/size.rb index cc207e3fa..b503aa09e 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/size.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/size.rb @@ -2,19 +2,18 @@ # size.rb # -# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ... - module Puppet::Parser::Functions newfunction(:size, :type => :rvalue, :doc => <<-EOS -Returns the number of elements in a string or array. +Returns the number of elements in a string, an array or a hash 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.size < 1 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 +27,13 @@ Returns the number of elements in a string or array. # 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')