       defaults
 
   scrubValue: (keyPath, value) ->
-    value = @constructor.executeSchemaValidators(value, schema) if schema = @getSchema(keyPath)
+    value = @constructor.executeSchemaValidators(keyPath, value, schema) if schema = @getSchema(keyPath)
     value
 
 # Base schema validators. These will coerce raw input into the specified type,

# specification.
Config.addSchemaValidators
  'integer':
    coercion: (value, schema) ->
      value = parseInt(value)
      throw new Error('Value cannot be coerced into an int') if isNaN(value)
      value

  'number':
    coercion: (value, schema) ->
      value = parseFloat(value)
      throw new Error('Value cannot be coerced into a number') if isNaN(value)
      value

  'boolean':
    coercion: (value, schema) ->
      switch typeof value
        when 'string'
          value.toLowerCase() in ['true', 't']

        # Using `isEqual` for possibility of placing enums on array and object schemas
        return value if _.isEqual(possibleValue, value)

      throw new Error("Cannot set #{keyPath}, #{JSON.stringify(value)} is not one of #{JSON.stringify(possibleValues)}")

isPlainObject = (value) ->
  _.isObject(value) and not _.isArray(value) and not _.isFunction(value) and not _.isString(value)
