]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(maint) Validate input argument in a single location
authorAdrien Thebo <git@somethingsinistral.net>
Mon, 12 Aug 2013 19:52:17 +0000 (12:52 -0700)
committerAdrien Thebo <git@somethingsinistral.net>
Mon, 12 Aug 2013 19:56:00 +0000 (12:56 -0700)
lib/puppet/parser/functions/validate_slength.rb

index 34dfcf283ea517dabec194cabfa2ceeaab64eccc..7d534f3703e623a1224a35d74259a127d95fc325 100644 (file)
@@ -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 #{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