File: type.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (55 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

Puppet::Parser::Functions.newfunction(
  :type,
  :type => :rvalue,
  :arity => -1,
  :doc => <<~DOC
    Returns the data type of a given value with a given degree of generality.

    ```puppet
    type InferenceFidelity = Enum[generalized, reduced, detailed]

    function type(Any $value, InferenceFidelity $fidelity = 'detailed') # returns Type
    ```

     **Example:** Using `type`

     ``` puppet
     notice type(42) =~ Type[Integer]
     ```

     Would notice `true`.

     By default, the best possible inference is made where all details are retained.
     This is good when the type is used for further type calculations but is overwhelmingly
     rich in information if it is used in a error message.

     The optional argument `$fidelity` may be given as (from lowest to highest fidelity):

     * `generalized` - reduces to common type and drops size constraints
     * `reduced` - reduces to common type in collections
     * `detailed` - (default) all details about inferred types is retained

     **Example:** Using `type()` with different inference fidelity:

     ``` puppet
     notice type([3.14, 42], 'generalized')
     notice type([3.14, 42], 'reduced'')
     notice type([3.14, 42], 'detailed')
     notice type([3.14, 42])
     ```

     Would notice the four values:

     1. 'Array[Numeric]'
     2. 'Array[Numeric, 2, 2]'
     3. 'Tuple[Float[3.14], Integer[42,42]]]'
     4. 'Tuple[Float[3.14], Integer[42,42]]]'

     * Since 4.4.0

  DOC
) do |_args|
  Puppet::Parser::Functions::Error.is4x('type')
end