View Source JetExt.Ecto.Enum (jet_ext v0.3.0)

Defining an Enum Ecto type.

Parameterized Type

  iex> type = Ecto.ParameterizedType.init(JetExt.Ecto.Enum, values: [:foo, :bar])
  {
    :parameterized,
    {
      JetExt.Ecto.Enum,
      %{
        on_load: %{"BAR" => :bar, "FOO" => :foo},
        type: :string,
        on_cast: %{"BAR" => :bar, "FOO" => :foo, "bar" => :bar, "foo" => :foo},
        embed_as: :self,
        mappings: [foo: "foo", bar: "bar"],
        on_dump: %{foo: "FOO", bar: "BAR"}
      }
    }
  }

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

Functions

Link to this function

dump_values(schema, field)

View Source
@spec dump_values(module(), atom()) :: [String.t()] | [integer()]

Returns the possible dump values for a given schema and field

@spec mappings(module(), atom()) :: Keyword.t()

Returns the mappings for a given schema and field

@spec values(module(), atom()) :: [atom()]

Returns the possible values for a given schema and field