Enumex.Dynamic.Components.Typespecs (Enumex v1.0.0)

View Source

Generates type specifications for enum definitions. This component automatically generates a t/0 type that represents your enum values, so you don't need to worry about the underlying field types.

Usage

defmodule MyApp.MyEnums do
  use Enumex.Dynamic, components: [
    # or any other component that defines a struct
    Enumex.Dynamic.Components.EctoSchema,
    Enumex.Dynamic.Components.Typespecs
  ]

  enum RenamedField, :renamed_fields, enum_name: :name, id: :value, index: :order do
    # you only need to use 3 vars no matter what types they contain
    @type t(name, value, order) :: %__MODULE__{
      __meta__:  Ecto.Schema.Metadata .t()
      # you can name them as you wish and assign them to any field
      name: name,
      order: order,
      value: value,
      # your custom field typespec goes hee
    }
  end
end

iex> t MyApp.MyEnums.RenamedField.t/0
@type t() :: t(Enumex.Value.enum_name(), Enumex.Value.id(), Enumex.Value.index())