exvalibur v0.10.0 Exvalibur.Guards.Default View Source
Default set of guards to be used with Exvalibur.validator!/2
.
Guards are public functions of arity 2, exporting the AST valid as Elixir guard. One might provide their own set of guards by the following config:
config :exvalibur, :guards, MyApp.Guards
Assuming that the file itself looks somewhat like:
defmodule MyApp.Guards do
import Exvalibur.Guards.Default, except: [min_length: 2]
def min_length(var, val) when is_integer(val) do
quote do
is_bitstring(unquote(var)) and byte_size(unquote(var)) >= unquote(val)
end
end
end
Link to this section Summary
Functions
Guard for conditions like %{eq: 1.0}
, exact equality
Guard for conditions like %{greater_than: 1.0}
, like min/2
, but the inequality is strict
Guard for conditions like %{less_than: 1.0}
, like max/2
, but the inequality is strict
Guard for conditions like %{max: 2.0}
, implies actual value is less or equal than the parameter
Guard for conditions like %{max_count: 10}
, checks the number of elements in list parameter
Guard for conditions like %{max_length: 10}
, checks the byte length of the binary parameter
Guard for conditions like %{min: 1.0}
, implies actual value is greater or equal than the parameter
Guard for conditions like %{min_count: 10}
, checks the number of elements in list parameter
Guard for conditions like %{min_length: 10}
, checks the byte length of the binary parameter
Guard for checking the excludion from the list like %{not_one_of: [42, 3.14]}
Guard for checking the includion in the list like %{one_of: [42, 3.14]}
Multi-clause function to convert binary representation to guard
Link to this section Functions
eq(var, val) View Source
Guard for conditions like %{eq: 1.0}
, exact equality
greater_than(var, val) View Source
Guard for conditions like %{greater_than: 1.0}
, like min/2
, but the inequality is strict
less_than(var, val) View Source
Guard for conditions like %{less_than: 1.0}
, like max/2
, but the inequality is strict
max(var, val) View Source
Guard for conditions like %{max: 2.0}
, implies actual value is less or equal than the parameter
max_count(var, val) View Source
Guard for conditions like %{max_count: 10}
, checks the number of elements in list parameter
max_length(var, val) View Source
Guard for conditions like %{max_length: 10}
, checks the byte length of the binary parameter
min(var, val) View Source
Guard for conditions like %{min: 1.0}
, implies actual value is greater or equal than the parameter
min_count(var, val) View Source
Guard for conditions like %{min_count: 10}
, checks the number of elements in list parameter
min_length(var, val) View Source
Guard for conditions like %{min_length: 10}
, checks the byte length of the binary parameter
not_one_of(var, val) View Source
Guard for checking the excludion from the list like %{not_one_of: [42, 3.14]}
one_of(var, val) View Source
Guard for checking the includion in the list like %{one_of: [42, 3.14]}
traverse_conditions(ast, acc \\ %{}) View Source
Multi-clause function to convert binary representation to guard