Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / length.rb
1 # @summary
2 #   **Deprecated:** A function to eventually replace the old size() function for stdlib
3 #
4 # The original size() function did not handle Puppets new type capabilities, so this function
5 # is a Puppet 4 compatible solution.
6 #
7 # > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a
8 # built-in [`length`](https://puppet.com/docs/puppet/latest/function.html#length) function.
9 #
10 Puppet::Functions.create_function(:length) do
11   # @param value
12   #   The value whose length is to be found
13   #
14   # @return [Integer]
15   #   The length of the given object
16   dispatch :length do
17     param 'Variant[String,Array,Hash]', :value
18   end
19   def length(value)
20     if value.is_a?(String)
21       result = value.length
22     elsif value.is_a?(Array) || value.is_a?(Hash)
23       result = value.size
24     end
25     result
26   end
27 end