validex v0.6.1 Validex
Validex is a library for doing data validation in Elixir. Using a schema you
specify what rules each attribute in your schema should be validated against.
Each rule is implemented as a combination of Validex.Validator
validators.
Before a schema is used for verification it is expanded, the purpose of the
expansion is twofold. First it translate syntactic shorthands into a proper
schema acceptable by Validex.Validator
and secondly it allows for adding
default unspecified rules to each attribute in the schema. Expansion happens
using modules that implements the Validex.RuleExpander
behaviour.
By default all attributes in a schema are assumed to be required and are thus
validated against the Validex.Validators.Presence
validator, this happens because
Validex.Validators.Presence
also expands each spec to include a presence
check.
Summary
Functions
Verify data against schema returning only invalid validations
Expands a rule using modules implementing the Validex.RuleExpander
behaviour. Optionally you can specify expanders to use in addition
to the built in expanders. Expansion happens
Verify data against schema returning false if any errors were found, otherwise it returns true
Verify data against schema returning both valid and invalid validations
Functions
Verify data against schema returning only invalid validations
Examples
iex> Validex.errors(%{ name: 5 }, [name: :string])
[{:error, :name, :type, "name should be string but was integer"}]
Expands a rule using modules implementing the Validex.RuleExpander
behaviour. Optionally you can specify expanders to use in addition
to the built in expanders. Expansion happens
Examples
iex> Validex.expand(:string)
[presence: :__validex_default_presence, type: :string]
iex> Validex.expand(%{ name: :string })
[presence: :__validex_default_presence, type: :map, nested: %{ name: :string }]