DryValidation.Types.Func (dry_validation v1.0.0)

Provides a way to define custom validation functions. It is a struct with:

  • fn that stores a function with one argument, that is used validate the input value
  • type is optional, used for casting values against that type before validating
  • error_message is error message returned in case of failed validation
DryValidation.schema do
  required :pet, Types.Func.member_of(["dog", "cat", "bird"])
end

Link to this section Summary

Functions

Validates that the input value is equal to the first argument.

Validates that the value is part of the list.

Link to this section Functions

Link to this function

cast(func, value)

Link to this function

equal(expected)

Validates that the input value is equal to the first argument.

DryValidation.schema do
  required :type, Types.Func.equal("user")
end
Link to this function

member_of(list)

Validates that the value is part of the list.

DryValidation.schema do
  required :pet, Types.Func.member_of(["dog", "cat", "bird"])
end