# Dredd

Dredd judges structs; it's a validator.

Dredd was forked from [Justify][2]

Inspired heavily by [Ecto.Changeset][1], Dredd allows you to pipe a plain map
into a series of validation functions using a simple and familiar API. No
schemas or casting required.


### Example

dataset =
  %{email: "this_is_not_an_email"}
  |> Dredd.validate_required(:email)
  |> Dredd.validate_format(:email, ~r/\S+@\S+/)

dataset.errors #=> [email: {"has invalid format", validation: :format}]
dataset.valid? #=> false

Each validation function will return a `Dredd.Dataset` struct which can be
passed into the next function. If a validation error is encountered the dataset
will be marked as invalid and an error will be added to the struct.

## Custom Validations

You can provide your own custom validations using the `Dredd.add_error/4`

### Example

defmodule MyValidator do
  def validate_color(data, field, color) do
    dataset =

    value = Map.get(, :field)

    if value == color do
      Dredd.add_error(dataset, field, "wrong color", validation: :color)

Your custom validation can be used as part of a validation pipeline.

### Example

dataset =
  %{color: "brown"}
  |> Dredd.validation_required(:color)
  |> MyValidator.validate_color(:color, "green")

dataset.errors #=> [color: {"wrong color", validation: :color}]
dataset.valid? #=> false

## Supported Validations

* [`validate_acceptance/3`](
* [`validate_confirmation/3`](
* [`validate_embed/3`](
* [`validate_exclusion/4`](
* [`validate_format/4`](
* [`validate_inclusion/4`](
* [`validate_length/3`](
* [`validate_required/3`](
* [`validate_type/4`](

## Copyright and License

Copyright (c) 2021 Anthoniy Smith

Copyright (c) 2022 Marcus Autenrieth

Dredd is licensed under the MIT License, see for details.