From 24911db44ca086b00ce543f7da08e5176f7c93a8 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Mon, 12 Aug 2013 12:52:17 -0700 Subject: (maint) Validate input argument in a single location --- lib/puppet/parser/functions/validate_slength.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/puppet/parser/functions/validate_slength.rb') diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb index 34dfcf2..7d534f3 100644 --- a/lib/puppet/parser/functions/validate_slength.rb +++ b/lib/puppet/parser/functions/validate_slength.rb @@ -25,10 +25,6 @@ module Puppet::Parser::Functions input, max_length, min_length = *args - unless (input.is_a?(String) or input.is_a?(Array)) - raise Puppet::ParseError, "validate_slength(): Expected first argument to be a String or Array, got a #{input.class}" - end - begin max_length = Integer(max_length) raise ArgumentError if max_length <= 0 @@ -62,12 +58,14 @@ module Puppet::Parser::Functions validator.call(input) when Array input.each_with_index do |arg, pos| - if arg.is_a?(String) + if arg.is_a? String validator.call(arg) else - raise Puppet::ParseError, "validate_slength(): Expected element at array position #{pos} to be a String, got a #{arg.class}" + raise Puppet::ParseError, "validate_slength(): Expected element at array position #{pos} to be a String, got #{arg.class}" end end + else + raise Puppet::ParseError, "validate_slength(): Expected first argument to be a String or Array, got #{input.class}" end end end -- cgit v1.2.3