View Source Construct.Types.Enum (Construct v3.0.2)
Implements an abstract enum type.
Usage
defmodule MyApp.Order do
use Construct do
field :type, {Construct.Types.Enum, [:delivery, :pickup]}
end
end
Then you can validate that :type
field accepts only specified
values.
iex> MyApp.Order.make(%{type: :delivery})
{:ok, %MyApp.Order{type: :delivery}}
iex> MyApp.Order.make(%{type: :other})
{:error, %{type: passed_value: :other, valid_values: [:delivery, :pickup]}}