Mercurial > repos > other > Puppet
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 |
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 | 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 | 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 |