View Source JetExt.Ecto.Enum (jet_ext v0.2.5)
Defining an Enum Ecto type.
Parameterized Type
iex> type = Ecto.ParameterizedType.init(JetExt.Ecto.Enum, values: [:foo, :bar])
{
:parameterized,
JetExt.Ecto.Enum,
%{
mappings: [foo: "foo", bar: "bar"],
on_cast: %{"FOO" => :foo, "BAR" => :bar, "foo" => :foo, "bar" => :bar},
on_dump: %{foo: "FOO", bar: "BAR"},
on_load: %{"FOO" => :foo, "BAR" => :bar},
type: :string
}
}
Type Module
defmodule EnumType do
use JetExt.Ecto.Enum, [:foo, :bar, :baz]
end
# cast
iex> EnumType.cast("foo")
{:ok, :foo}
iex> EnumType.cast("FOO")
{:ok, :foo}
iex> EnumType.cast(:foo)
{:ok, :foo}
# load
iex> EnumType.load("foo")
{:ok, :foo}
iex> EnumType.load("FOO")
{:ok, :foo}
# dump
iex> EnumType.dump(:foo)
{:ok, "FOO"}
Summary
Functions
Returns the possible dump values for a given schema and field
Returns the mappings for a given schema and field
Returns the possible values for a given schema and field
Types
@type t() :: atom()
Functions
Returns the possible dump values for a given schema and field
Returns the mappings for a given schema and field
Returns the possible values for a given schema and field