|
2 | 2 | # The function checks a value against both the target_type (new) and the previous_validation function (old). |
3 | 3 |
|
4 | 4 | dispatch :validate_legacy do |
| 5 | + scope_param |
5 | 6 | param 'Type', :target_type |
6 | | - param 'String', :previous_validation |
7 | | - param 'NotUndef', :value |
8 | | - optional_param 'Any', :args |
| 7 | + param 'String', :function_name |
| 8 | + param 'Any', :value |
| 9 | + optional_repeated_param 'Any', :args |
9 | 10 | end |
| 11 | + |
10 | 12 | dispatch :validate_legacy_s do |
11 | 13 | scope_param |
12 | 14 | param 'String', :type_string |
13 | | - param 'String', :previous_validation |
14 | | - param 'NotUndef', :value |
| 15 | + param 'String', :function_name |
| 16 | + param 'Any', :value |
15 | 17 | optional_repeated_param 'Any', :args |
16 | 18 | end |
17 | 19 |
|
18 | 20 | def validate_legacy_s(scope, type_string, *args) |
19 | 21 | t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope) |
20 | | - validate_legacy(t, *args) |
| 22 | + validate_legacy(scope, t, *args) |
21 | 23 | end |
22 | 24 |
|
23 | | - def validate_legacy(target_type, previous_validation, value, *prev_args) |
| 25 | + def validate_legacy(scope, target_type, function_name, value, *prev_args) |
24 | 26 | if assert_type(target_type, value) |
25 | | - if previous_validation(previous_validation, value, *prev_args) |
| 27 | + if previous_validation(scope, function_name, value, *prev_args) |
26 | 28 | # Silently passes |
27 | 29 | else |
28 | | - Puppet.warn("Accepting previously invalid value for target_type '#{target_type}'") |
| 30 | + Puppet.notice("Accepting previously invalid value for target type '#{target_type}'") |
29 | 31 | end |
30 | 32 | else |
31 | 33 | caller_infos = caller.first.split(":") |
32 | 34 | inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value) |
33 | | - message = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch(previous_validation, target_type, inferred_type) |
34 | | - error_msg = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}" |
35 | | - if previous_validation(previous_validation, value, *prev_args) |
36 | | - Puppet.warn(error_msg) |
| 35 | + error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{function_name}) [#{caller_infos[0]}:#{caller_infos[1]}]", target_type, inferred_type) |
| 36 | + if previous_validation(scope, function_name, value, *prev_args) |
| 37 | + call_function('deprecation', 'validate_legacy', error_msg) |
37 | 38 | else |
38 | 39 | call_function('fail', error_msg) |
39 | 40 | end |
40 | 41 | end |
41 | 42 | end |
42 | 43 |
|
43 | | - def previous_validation(previous_validation, value, *prev_args) |
| 44 | + def previous_validation(scope, function_name, value, *prev_args) |
44 | 45 | # Call the previous validation function and catch any errors. Return true if no errors are thrown. |
45 | 46 | begin |
46 | | - call_function(previous_validation, value, *prev_args) |
| 47 | + scope.send("function_#{function_name}".to_s, [value, *prev_args]) |
47 | 48 | true |
48 | 49 | rescue Puppet::ParseError |
49 | 50 | false |
|
0 commit comments