michaelklishin/validateur — pull request #38 by sritchie (2014-12-14 12:35:17+00:00)
Title: validate-some and errors?

From my changelog updates:

### validate-some

`validate-some` tries any number of validators, short-circuiting at the first failed validator. This behavior is similar to `or`.

```clojure
(require '[validateur.validation :refer :all])

(let [v (validate-some
(presence-of :cake-count :message "missing_cake")
(validate-by :cake-count odd? :message "even_cake"))]

"Odd cake counts are valid."
(v {:cake-count 1})
;;=> [true #{}]

"Even cake counts only throw the second error, since the first
validation passed."
(v {:cake-count 2})
;;=> [false {:cake-count #{"even_cake"}}]

"The second validation never gets called and never throws a NPE, as
it would if we just composed them up."
(v {})
;;=> [false {:cake-count #{"missing_cake"}}]
)
```

### errors? and errors

Errors in validateur are vectors if keys are nested. If keys are only one layer deep - `:cake`, for example - the error can live at `:cake` or `[:cake]`.

The `errors` function returns the set of errors for some key, nested or bare. `:cake` will return errors stored under `[:cake]` and vice-versa.

`errors?` is a boolean wrapper that returns true if some key has errors, false otherwise.