lib/soar_sr/validator.rb in soar_sr-0.1.3 vs lib/soar_sr/validator.rb in soar_sr-0.1.4

- old
+ new

@@ -12,17 +12,21 @@ raise ValidationError, "invalid #{label} provided" if (field.is_a?(String) and field.strip == "") true end def key_provided?(field, key, label) - raise ValidationError, "no #{label} provided" if field.nil? or field[key].nil? - raise ValidationError, "invalid #{label} provided" if ((not field.is_a? Hash) or (field[key].strip == "")) + msg_no = "no #{label} provided" + msg_invalid = "invalid #{label} provided" + raise ValidationError, msg_no if field.nil? + raise ValidationError, msg_invalid if (not field.is_a? Hash) + raise ValidationError, msg_no if field[key].nil? + raise ValidationError, msg_invalid if (not field[key].is_a? String) or (field[key].strip == "") true end def length_at_least?(field, min, label) - raise ValidationError, "invalid #{label} provided" if (field.size < 4) + raise ValidationError, "invalid #{label} provided" if (field.size < min) true end def credentials?(credentials) provided?(credentials['username'], 'username') and provided?(credentials['password'], 'password')