examine.core

Function for creation of rule-sets, validating, and using validation results

has-errors?

(has-errors? validation-results)
Returns true if the validation results contain at least
one not-nil message.

map-data-provider

(map-data-provider m keyword-or-vector)
Default data provider that uses get or get-in to retrieve
data from a map/record.

messages

(messages validation-results)(messages localizer-fn validation-results)
Returns a map {path -> sequence-of-human-readable-strings}.
If the localizer-fn is not given the default-localizer is used.

messages-for

(messages-for path validation-results)(messages-for localizer-fn path validation-results)
Returns a sequence of human readable strings for the given path.
If the localizer-fn is not given the default-localizer is used.

rule-set

(rule-set & specs)
Creates a rule-set from paths, constraints and conditions.

The general structure of `specs` is:
  path constraints-and-conditions+
  path constraints-and-conditions+

A path points to data. It can either be a key, or a vector
containing keys. n paths are grouped by a vector to specify
multiple data locations that apply to n-arg constraints.

Examples:
:foo
   Specifies a path to value in {:foo value}
[:foo :bar]
  Specifies 2 paths to values in {:foo value1 :bar value2}
[[:foo :bar]]
   Specifies a single path pointing to value in {:foo {:bar value}}
[:foo [:bar :baz :bum]]
   Specifies 2 paths in {:foo value1 :bar {:baz {:bum value2}}}

Constraints are 1-arg functions that return a string to flag
a constraint violation for the given value.

Conditions are 1-arg predicates that stop application of subsequent
constraints.

Example:
  (rule-set :foo required (min-length 3)
            [[:bar :baz]] number? (in-range 0 10))

sub-set

(sub-set rule-set & ps)
Returns the subset of the rule-set that contains only those
rules that reference at least one of the paths given in ps.

update

(update old-map new-map)
Takes two validation results (or any map) and recursively updates
the first with all values of the second. Existing values of the
first are kept.

validate

(validate rule-set data)(validate data-provider rule-set data)
Creates validation results by applying the constraints of the rule-set
to the data. If the data-provider arg is missing the map-data-provider
is used.