Exop v0.4.1 Exop.ValidationChecks

Provides low-level validation functions:

  • check_type/3
  • check_required/3
  • check_numericality/3
  • check_in/3
  • check_not_in/3
  • check_format/3
  • check_length/3

Summary

Functions

Checks whether an item_name conforms the given format

Checks whether an item is valid over custom validation function

Checks whether an item_name is a memeber of a list

Checks an item_name over length constraints

Checks whether an item_name is not a memeber of a list

Checks an item_name over numericality constraints

Checks if an item_name presents in params if its required (true)

Checks whether an item is expected structure

Checks the type of an item_name

Returns an item_name from either a Keyword or a Map by an atom-key

Types

check_error :: %{optional(atom) => String.t}

Functions

check_format(check_items, item_name, check)

Specs

check_format(Keyword.t | map, atom, Regex.t) ::
  true |
  check_error

Checks whether an item_name conforms the given format.

Examples

iex> Exop.ValidationChecks.check_format(%{a: “bar”}, :a, ~r/bar/) true

check_func(check_items, item_name, check)

Specs

check_func(Keyword.t | map, atom, (any -> true | false)) ::
  true |
  check_error

Checks whether an item is valid over custom validation function.

check_in(check_items, item_name, check_list)

Specs

check_in(Keyword.t | map, atom, list) ::
  true |
  check_error

Checks whether an item_name is a memeber of a list.

Examples

iex> Exop.ValidationChecks.check_in(%{a: 1}, :a, [1, 2, 3]) true

check_length(check_items, item_name, checks)

Specs

check_length(Keyword.t | map, atom, map) ::
  true |
  [check_error]

Checks an item_name over length constraints.

Examples

iex> Exop.ValidationChecks.check_length(%{a: “123”}, :a, %{min: 0}) [true]

iex> Exop.ValidationChecks.check_length(%{a: ~w(1 2 3)}, :a, %{in: 2..4}) [true]

iex> Exop.ValidationChecks.check_length(%{a: ~w(1 2 3)}, :a, %{is: 3, max: 4}) [true, true]

check_not_in(check_items, item_name, check_list)

Specs

check_not_in(Keyword.t | map, atom, list) ::
  true |
  check_error

Checks whether an item_name is not a memeber of a list.

Examples

iex> Exop.ValidationChecks.check_not_in(%{a: 4}, :a, [1, 2, 3]) true

check_numericality(check_items, item_name, checks)

Specs

check_numericality(Keyword.t | map, atom, map) ::
  true |
  check_error

Checks an item_name over numericality constraints.

Examples

iex> Exop.ValidationChecks.check_numericality(%{a: 3}, :a, %{ equal_to: 3 }) true

iex> Exop.ValidationChecks.check_numericality(%{a: 5}, :a, %{ greater_than_or_equal_to: 3 }) true

iex> Exop.ValidationChecks.check_numericality(%{a: 3}, :a, %{ less_than_or_equal_to: 3 }) true

check_required(check_items, item_name, bool)

Specs

check_required(Keyword.t | map, atom, boolean) ::
  true |
  check_error

Checks if an item_name presents in params if its required (true).

Examples

iex> Exop.ValidationChecks.check_required(%{}, :some_item, false) true

iex> Exop.ValidationChecks.check_required([a: 1, b: 2], :a, true) true

iex> Exop.ValidationChecks.check_required(%{a: 1, b: 2}, :b, true) true

check_struct(check_items, item_name, check)

Specs

check_struct(Keyword.t | map, atom, struct) ::
  true |
  check_error

Checks whether an item is expected structure.

check_type(check_items, item_name, check)

Specs

check_type(Keyword.t | map, atom, atom) ::
  true |
  check_error

Checks the type of an item_name.

Examples

iex> Exop.ValidationChecks.check_type(%{a: 1}, :a, :integer) true

iex> Exop.ValidationChecks.check_type(%{a: “1”}, :a, :string) true

get_check_item(check_items, item_name)

Specs

get_check_item(Keyword.t | map, atom) :: any | nil

Returns an item_name from either a Keyword or a Map by an atom-key.

Examples

iex> Exop.ValidationChecks.get_check_item(%{a: 1, b: 2}, :a) 1

iex> Exop.ValidationChecks.get_check_item([a: 1, b: 2], :b) 2

iex> Exop.ValidationChecks.get_check_item(%{a: 1, b: 2}, :c) nil