Exop v0.3.2 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_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 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
Specs
check_format(Keyword.t | Map.t, 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
Specs
check_in(Keyword.t | Map.t, 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
Specs
check_length(Keyword.t | Map.t, atom, Map.t) ::
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]
Specs
check_not_in(Keyword.t | Map.t, 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
Specs
check_numericality(Keyword.t | Map.t, atom, Map.t) ::
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
Specs
check_required(Keyword.t | Map.t, 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
Specs
check_struct(Keyword.t | Map.t, atom, struct) ::
true |
check_error
Specs
check_type(Keyword.t | Map.t, 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
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