-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathtype3x.rb
More file actions
52 lines (41 loc) · 1.29 KB
/
type3x.rb
File metadata and controls
52 lines (41 loc) · 1.29 KB
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
# frozen_string_literal: true
#
# type3x.rb
#
module Puppet::Parser::Functions
newfunction(:type3x, type: :rvalue, doc: <<-DOC
@summary
**DEPRECATED:** This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system.
@return the type when passed a value. Type can be one of:
* string
* array
* hash
* float
* integer
* boolean
DOC
) do |args|
raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1
value = args[0]
klass = value.class
unless [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) # rubocop:disable Lint/UnifiedInteger
raise(Puppet::ParseError, 'type3x(): Unknown type')
end
klass = klass.to_s # Ugly ...
# We note that Integer is the parent to Bignum and Fixnum ...
result = case klass
when %r{^(?:Big|Fix)num$} then 'integer'
when %r{^(?:True|False)Class$} then 'boolean'
else klass
end
if result == 'String'
if value == value.to_i.to_s
result = 'Integer'
elsif value == value.to_f.to_s
result = 'Float'
end
end
return result.downcase
end
end
# vim: set ts=2 sw=2 et :