docs: Clarify how to use Enums in attributes (#790)

This commit is contained in:
Igor Barakaiev 2023-12-03 04:34:23 +01:00 committed by GitHub
parent 728226bfee
commit 0ae14bdf71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,12 +2,12 @@ defmodule Ash.Type.Enum do
@moduledoc """ @moduledoc """
A type for abstracting enums into a single type. A type for abstracting enums into a single type.
For example, your existing app might look like: For example, your existing attribute might look like:
```elixir ```elixir
attribute :status, :atom, constraints: [one_of: [:open, :closed]] attribute :status, :atom, constraints: [one_of: [:open, :closed]]
``` ```
But as that starts to spread around your system you may find that you want 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 to centralize that logic. To do that, use this module to define an Ash type
easily: easily:
@ -17,6 +17,12 @@ defmodule Ash.Type.Enum do
end end
``` ```
Then, you can rewrite your original attribute as follows:
```elixir
attribute :status, MyApp.TicketStatus
```
Valid values are: Valid values are:
* The atom itself, e.g `:open` * The atom itself, e.g `:open`