commanded_messaging v0.2.1 Commanded.Command behaviour View Source
Creates an Ecto.Schema.embedded_schema
that supplies a command with all the validation power of the Ecto.Changeset
data structure.
defmodule CreateAccount do
use Commanded.Command,
username: :string,
email: :string,
age: :integer
def handle_validate(changeset) do
changeset
|> validate_required([:username, :email, :age])
|> validate_format(:email, ~r/@/)
|> validate_number(:age, greater_than: 12)
end
end
iex> CreateAccount.new(username: "chris", email: "chris@example.com", age: 5)
#Ecto.Changeset<action: nil, changes: %{age: 5, email: "chris@example.com", username: "chris"}, errors: [age: {"must be greater than %{number}", [validation: :number, kind: :greater_than, number: 12]}], data: #CreateAccount<>, valid?: false>
Link to this section Summary
Callbacks
Optional callback to define validation rules
Link to this section Functions
Link to this section Callbacks
Link to this callback
handle_validate(arg1)
View Sourcehandle_validate(Ecto.Changeset.t()) :: Ecto.Changeset.t()
Optional callback to define validation rules