exvalibur v0.3.1 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 bytesize(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_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_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]}

Link to this section Functions

Link to this function eq(var, val) View Source
eq(any(), number()) :: {:and, list(), list()}

Guard for conditions like %{eq: 1.0}, exact equality

Link to this function greater_than(var, val) View Source
greater_than(any(), number()) :: {:and, list(), list()}

Guard for conditions like %{greater_than: 1.0}, like min/2, but the inequality is strict

Link to this function less_than(var, val) View Source
less_than(any(), number()) :: {:and, list(), list()}

Guard for conditions like %{less_than: 1.0}, like max/2, but the inequality is strict

Link to this function max(var, val) View Source
max(any(), number()) :: {:and, list(), list()}

Guard for conditions like %{max: 2.0}, implies actual value is less or equal than the parameter

Link to this function max_length(var, val) View Source
max_length(any(), integer()) :: {:and, list(), list()}

Guard for conditions like %{max_length: 10}, checks the byte length of the binary parameter

Link to this function min(var, val) View Source
min(any(), number()) :: {:and, list(), list()}

Guard for conditions like %{min: 1.0}, implies actual value is greater or equal than the parameter

Link to this function min_length(var, val) View Source
min_length(any(), integer()) :: {:and, list(), list()}

Guard for conditions like %{min_length: 10}, checks the byte length of the binary parameter

Link to this function not_one_of(var, val) View Source
not_one_of(any(), list()) :: {:not, list(), [{:in, list(), list()}]}

Guard for checking the excludion from the list like %{not_one_of: [42, 3.14]}

Link to this function one_of(var, val) View Source
one_of(any(), list()) :: {:in, list(), list()}

Guard for checking the includion in the list like %{one_of: [42, 3.14]}