Cqrs.ValueObject behaviour (cqrs_tools v0.5.28) View Source

The ValueObject macro allows you to define a typed struct with validation.

Options

  • require_all_fields (:boolean) - If true, all fields will be required. Defaults to true

Link to this section Summary

Functions

Defines a value object field.

Callbacks

Allows one to modify the fully validated command. The changes to the command are validated again after this callback.

Allows one to define any custom data validation aside from casting and requiring fields.

Link to this section Functions

Link to this macro

field(name, type, opts \\ [])

View Source (macro)

Specs

field(name :: atom(), type :: atom(), keyword()) :: any()

Defines a value object field.

  • :name - any atom

  • :type - any valid Ecto Schema type

  • :opts - any valid Ecto Schema field options. Plus:

    • :required - true | false. Defaults to the require_all_fields option.
    • :description - Documentation for the field.

Link to this section Callbacks

Specs

after_validate(struct()) :: struct()

Allows one to modify the fully validated command. The changes to the command are validated again after this callback.

This callback is optional.

Invoked after the handle_validate/2 callback is called.

Link to this callback

handle_validate(arg1, keyword)

View Source

Specs

handle_validate(
  Ecto.Changeset.t(),
  keyword()
) :: Ecto.Changeset.t()

Allows one to define any custom data validation aside from casting and requiring fields.

This callback is optional.

Invoked when the new() or new!() function is called.