summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHunter Haugen <hunter@puppet.com>2016-09-07 08:56:29 -0700
committerGitHub <noreply@github.com>2016-09-07 08:56:29 -0700
commitdce8d7b194e3f6d9bb24e076c6e835aeb671099a (patch)
treee223708e8404e6e52d4c2fafef3322bfea7f2ee7 /lib
parentd350ee49ee318353e9aa596c254ffbc40eba5b8d (diff)
parentf1edd2715a755573d7578839a3efe8473b79b5c5 (diff)
Merge pull request #649 from DavidS/modules-3737
(MODULES-3737) refactor validate_legacy and tests
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/functions/validate_legacy.rb31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/puppet/functions/validate_legacy.rb b/lib/puppet/functions/validate_legacy.rb
index b1066e2..0ba6dd8 100644
--- a/lib/puppet/functions/validate_legacy.rb
+++ b/lib/puppet/functions/validate_legacy.rb
@@ -2,48 +2,49 @@ Puppet::Functions.create_function(:validate_legacy, Puppet::Functions::InternalF
# The function checks a value against both the target_type (new) and the previous_validation function (old).
dispatch :validate_legacy do
+ scope_param
param 'Type', :target_type
- param 'String', :previous_validation
- param 'NotUndef', :value
- optional_param 'Any', :args
+ param 'String', :function_name
+ param 'Any', :value
+ optional_repeated_param 'Any', :args
end
+
dispatch :validate_legacy_s do
scope_param
param 'String', :type_string
- param 'String', :previous_validation
- param 'NotUndef', :value
+ param 'String', :function_name
+ param 'Any', :value
optional_repeated_param 'Any', :args
end
def validate_legacy_s(scope, type_string, *args)
t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope)
- validate_legacy(t, *args)
+ validate_legacy(scope, t, *args)
end
- def validate_legacy(target_type, previous_validation, value, *prev_args)
+ def validate_legacy(scope, target_type, function_name, value, *prev_args)
if assert_type(target_type, value)
- if previous_validation(previous_validation, value, *prev_args)
+ if previous_validation(scope, function_name, value, *prev_args)
# Silently passes
else
- Puppet.warn("Accepting previously invalid value for target_type '#{target_type}'")
+ Puppet.notice("Accepting previously invalid value for target type '#{target_type}'")
end
else
caller_infos = caller.first.split(":")
inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
- message = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch(previous_validation, target_type, inferred_type)
- error_msg = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
- if previous_validation(previous_validation, value, *prev_args)
- Puppet.warn(error_msg)
+ error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{function_name}) [#{caller_infos[0]}:#{caller_infos[1]}]", target_type, inferred_type)
+ if previous_validation(scope, function_name, value, *prev_args)
+ call_function('deprecation', 'validate_legacy', error_msg)
else
call_function('fail', error_msg)
end
end
end
- def previous_validation(previous_validation, value, *prev_args)
+ def previous_validation(scope, function_name, value, *prev_args)
# Call the previous validation function and catch any errors. Return true if no errors are thrown.
begin
- call_function(previous_validation, value, *prev_args)
+ scope.send("function_#{function_name}".to_s, [value, *prev_args])
true
rescue Puppet::ParseError
false