 
     if isValid @query, "object"
       queryTypes = @query
-
       Object.keys(queryTypes).forEach (key) ->
-        type = queryTypes[key]
-        if type is Number
-          queryTypes[key] = stringToNumber
-        else if type is Boolean
-          queryTypes[key] = stringToBoolean
-        return
-
+        queryTypes[key] = valido.get queryTypes[key]
       return (req, res) -> Promise.try ->
-        return error if error = validateTypes req.query, queryTypes
+        return error if error = validateQuery req.query, queryTypes
         return responder.call req, req.query, res
 
     if @body is yes

#
# Helpers
#

stringToNumber = (query, key) ->
  value = parseInt query[key]

  if isNaN value
    return Error "Expected '#{key}' to be a Number"

  query[key] = value
  return

stringToBoolean = (query, key) ->
  value = query[key]

  if (value is "") or (value is "true")
    value = yes

  else if (value is undefined) or (value is "false")
    value = no

  if isValid value, "boolean"
    query[key] = value
    return

  return Error "Expected '#{key}' to be a Boolean"

createRegex = (pattern) ->
  paramRE = /:[^\/]+/gi


validateTypes = (obj, types) ->
  for key, type of types
    error = type.assert obj[key]
    return error key if error
  return

validateQuery = (obj, types) ->
  for key, type of types
    coalesce obj, key, type.name
    error = type.assert obj[key]
    return error key if error
  return

coalesce = (obj, key, type) ->
  value = obj[key]
  switch type

    when "number"
      value = parseInt value
      unless isNaN value
        obj[key] = value

    when "boolean"

      if (value is undefined) or (value is "false")
        obj[key] = false

      else if (value is "") or (value is "true")
        obj[key] = true

  return
