View Source Dsv.Exclusion (Dsv v0.3.0)
Ensure a value is not on the forbidden values list. Dsv.Exclusion module provides functions to determine if a value is not present in a list.
Summary
Functions
The valid?/2 function evaluates whether a given value is not present in a list.
The validate/2 function evaluates whether a given value is not present in a list.
The validate/3 function evaluates whether a given value is not present in a list.
Functions
The valid?/2 function evaluates whether a given value is not present in a list.
Parameters
value- The value to be checked.list- The list in which the presence of the value is checked.
Returns
A boolean value:
trueifvalueis not present inlist.falseifvalueis present inlist.
Examples
iex> Dsv.Exclusion.valid?("test", ["a", :b, "c", %{a: :b}])
:true
iex> Dsv.Exclusion.valid?("test", ["test", :b, "c", %{a: :b}])
:false
iex> Dsv.Exclusion.valid?("test", [])
:true
iex> Dsv.Exclusion.valid?(nil, [nil, 1, 2, 3])
:false
iex> Dsv.Exclusion.valid?(nil, [1, 2, 3])
:true
The validate/2 function evaluates whether a given value is not present in a list.
Parameters
value- The value to be checked.list- The list in which the presence of the value is checked.
Returns
:okifvalueis not present inlist.{:error, message}ifvalueis present inlist.
Examples
iex> Dsv.Exclusion.validate("test", ["a", :b, "c", %{a: :b}])
:ok
iex> Dsv.Exclusion.validate("test", ["test", :b, "c", %{a: :b}])
{:error, ~s(Value "test" can't be on the list ["test", :b, "c", %{a: :b}])}
iex> Dsv.Exclusion.validate("test", [])
:ok
iex> Dsv.Exclusion.validate(nil, [nil, 1, 2, 3])
{:error, ~s(Value nil can't be on the list [nil, 1, 2, 3])}
iex> Dsv.Exclusion.validate(nil, [nil, 1, 2, 3], message: "Provided value is not allowed.")
{:error, "Provided value is not allowed."}
iex> Dsv.Exclusion.validate(nil, [1, 2, 3])
:ok
The validate/3 function evaluates whether a given value is not present in a list.
Parameters
value- The value to be checked.list- The list in which the presence of the value is checked.message- The message that will be returned in case of failure.
Returns
:okifvalueis not present inlist.{:error, message}ifvalueis present inlist.
Examples
iex> Dsv.Exclusion.validate(nil, [nil, 1, 2, 3], message: "Provided value is not allowed.")
{:error, "Provided value is not allowed."}
iex> Dsv.Exclusion.validate(nil, [nil, 1, 2, 3], "Provided value is not allowed.")
{:error, "Provided value is not allowed."}
iex> Dsv.Exclusion.validate(nil, [1, 2, 3], "Provided value is not allowed.")
:ok