annotate modules/stdlib/lib/puppet/functions/length.rb @ 275:d9352a684e62

Mass update of modules to remove deprecation warnings
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Jan 2020 11:36:07 +0000
parents c42fb28cff86
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
1 # @summary
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
2 # **Deprecated:** A function to eventually replace the old size() function for stdlib
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
3 #
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
4 # The original size() function did not handle Puppets new type capabilities, so this function
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
5 # is a Puppet 4 compatible solution.
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
6 #
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
7 # > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
8 # built-in [`length`](https://puppet.com/docs/puppet/latest/function.html#length) function.
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
9 #
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 Puppet::Functions.create_function(:length) do
275
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
11 # @param value
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
12 # The value whose length is to be found
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
13 #
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
14 # @return [Integer]
d9352a684e62 Mass update of modules to remove deprecation warnings
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
15 # The length of the given object
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 dispatch :length do
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 param 'Variant[String,Array,Hash]', :value
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 def length(value)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 if value.is_a?(String)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 result = value.length
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 elsif value.is_a?(Array) || value.is_a?(Hash)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 result = value.size
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 result
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 end
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 end