View Source OnePiece.Commanded.Enum (OnePiece.Commanded v0.22.0)

Defines an Enum type module.

Summary

Functions

Converts the module into a struct with an :value enum field.

Functions

__using__(opts)

(macro)

Converts the module into a struct with an :value enum field.

Using

Derives

Usage

defmodule BankAccountType do
  use OnePiece.Commanded.Enum, values: [:business, :personal]
end

{:ok, type} = BankAccountType.new(:business)

You can use it in your Ecto.Schema like this:

defmodule BankAccount do
  use Ecto.Schema

  embedded_schema do
    field :type, BankAccountType
  end
end