Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / type3x.rb
1 #
2 # type3x.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:type3x, :type => :rvalue, :doc => <<-DOC
6     DEPRECATED: This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system.
7
8     Returns the type when passed a value. Type can be one of:
9
10     * string
11     * array
12     * hash
13     * float
14     * integer
15     * boolean
16   DOC
17              ) do |args|
18     raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1
19
20     value = args[0]
21
22     klass = value.class
23
24     unless [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) # rubocop:disable Lint/UnifiedInteger
25       raise(Puppet::ParseError, 'type3x(): Unknown type')
26     end
27
28     klass = klass.to_s # Ugly ...
29
30     # We note that Integer is the parent to Bignum and Fixnum ...
31     result = case klass
32              when %r{^(?:Big|Fix)num$} then 'integer'
33              when %r{^(?:True|False)Class$} then 'boolean'
34              else klass
35              end
36
37     if result == 'String'
38       if value == value.to_i.to_s
39         result = 'Integer'
40       elsif value == value.to_f.to_s
41         result = 'Float'
42       end
43     end
44
45     return result.downcase
46   end
47 end
48
49 # vim: set ts=2 sw=2 et :