#
View Source Ash.Type.Enum behaviour (ash v2.4.22)

A type for abstracting enums into a single type.

For example, your existing app might look like:

    attribute :status, :atom, constraints: [one_of: [:open, :closed]]

But as that starts to spread around your system you may find that you want to centralize that logic. To do that, use this module to define an Ash type easily:

    defmodule MyApp.TicketStatus do
      use Ash.Type.Enum, values: [:open, :closed]
    end

Valid values are:

- The atom itself, e.g `:open`
- A string that matches the atom, e.g `"open"`
- A string that matches the atom after being downcased, e.g `"OPEN"` or `"oPeN"`
- A string that matches the stringified, downcased atom, after itself being downcased. This allows for enum values like `:Open`, `:SomeState` and `:Some_State`

# Link to this section Summary

## Callbacks

match(term)

finds the valid value that matches a given input term

match?(term)

true if a given term matches a value

values()

The list of valid values (not all input types that match them)

# Link to this section Callbacks

Link to this callback

# match(term)

View Source

    @callback match(term()) :: {:ok, atom()} | :error

finds the valid value that matches a given input term

Link to this callback

# match?(term)

View Source

    @callback match?(term()) :: boolean()

true if a given term matches a value

Link to this callback

# values()

View Source

    @callback values() :: [atom()]

The list of valid values (not all input types that match them)