Box.Generator behaviour (box v0.15.1)
View SourceBehaviour for generating random values. Generators needs to implement this behaviour.
Summary
Functions
Generates a unique value using the provided generator. Option :schema
is required to validate the presence of the value.
Types
@type generate_option() :: {:max_tries, non_neg_integer()} | {:exists?, (any() -> boolean())}
Module implementing the Galerie.Generator behaviour
Callbacks
Functions
@spec unique(generator(), [generate_option() | {atom(), any()}]) :: String.t()
Generates a unique value using the provided generator. Option :schema
is required to validate the presence of the value.
Example
iex> genereate(Alphanumerical, exists?: fn value -> Repo.exists?(where(Book, [book], book.code == ^value)) end)
The above example will validate that the generated value doesn't exist as
a :reset_password_token
in the User
scheme