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
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/puppet/functions/validate_legacy.rb', line 5
Puppet::Functions.create_function(:validate_legacy) do
dispatch :validate_legacy do
param 'Any', :scope
param 'Type', :target_type
param 'String', :function_name
param 'Any', :value
repeated_param 'Any', :args
end
dispatch :validate_legacy_s do
param 'Any', :scope
param 'String', :type_string
param 'String', :function_name
param 'Any', :value
repeated_param 'Any', :args
end
def call(scope, *args)
manipulated_args = [scope] + args
self.class.dispatcher.dispatch(self, scope, manipulated_args)
end
def validate_legacy_s(scope, type_string, *args)
t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope)
validate_legacy(scope, t, *args)
end
def validate_legacy(_scope, target_type, _function_name, value, *_prev_args)
call_function('deprecation', 'validate_legacy', 'This method is deprecated, please use Puppet data types to validate parameters')
if assert_type(target_type, value)
else
inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{target_type}, ...)", target_type, inferred_type)
call_function('fail', error_msg)
end
end
def assert_type(type, value)
Puppet::Pops::Types::TypeCalculator.instance?(type, value)
end
end
|