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

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

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