ApiCommons.Parameter.Constraints (ApiCommons v0.1.0) View Source

Check parameter for specific characterstics.

TODO:

- [ ] Add functions for :min, :max, :is and :count
- [ ] Add functions for :format, :inclusion, :exclusion
- [ ] Add functions for :less_than, :less_or_equal_to, :greater_than, :greater_or_equal_to and :equal_to

Link to this section Summary

Functions

Check if value of given parameter is in a given range. ^

Check whether or not the parameter is required for processing.

Cast a parameter value to specific type.

Validate constraints for a given parameter.

Link to this section Functions

Check if value of given parameter is in a given range. ^

Parameter

- param: Parameter struct encapsulating all information 

Returns: %Parameter{...}

Check whether or not the parameter is required for processing.

Parameter

- param: Parameter struct containing all information about a single parameter check

Returns: %Parameter{}

Specs

Cast a parameter value to specific type.

Examples

iex> param = %Parameter{name: :test, value: "12", type: :integer}
iex> cast(param)
%Parameter{
    name: :test,
    value: 12,
    valid?: true,
    opts: %{}}

iex> param = %Parameter{name: :test, value: "1k", type: :integer}
iex> cast(param)
%Parameter{
    name: :test,
    valuer: 12,
    valid?: false,
    errors: [:cast]}

Validate constraints for a given parameter.

Parameter

- param: `Parameter` struct encapsulating information

Returns: %Parameter{...}