arkgil/optium

Add support for validators

Closed this issue · 1 comments

Users should be able to provide validation functions to options schema, so that parsing fails if the function returns wrong result, e.g:

iex> schema = %{key: [required: true, validate_with: {&is_integer/1, "must be an integer"}}
iex> [key: 1] |> Optium.parse(schema)
{:ok, [key: 1]}
iex> [key: "hello"] |> Optium.parse(schema)
{:error, Optium.OptionInvalidError{key: :key, error_msg: "must be an integer"}}

Closed with 9aae84c