Box.Generator behaviour (box v0.15.1)

View Source

Behaviour for generating random values. Generators needs to implement this behaviour.

Summary

Types

Module implementing the Galerie.Generator behaviour

Functions

Generates a unique value using the provided generator. Option :schema is required to validate the presence of the value.

Types

generate_option()

@type generate_option() ::
  {:max_tries, non_neg_integer()} | {:exists?, (any() -> boolean())}

generator()

@type generator() :: {module(), Keyword.t()}

Module implementing the Galerie.Generator behaviour

Callbacks

generate(t)

@callback generate(Keyword.t()) :: String.t()

Functions

generate(arg)

generate(generator, options)

unique(generator, options)

@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