mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
docs: Clarify how to use Enums in attributes (#790)
This commit is contained in:
parent
728226bfee
commit
0ae14bdf71
1 changed files with 8 additions and 2 deletions
|
@ -2,12 +2,12 @@ defmodule Ash.Type.Enum do
|
|||
@moduledoc """
|
||||
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
|
||||
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
|
||||
easily:
|
||||
|
||||
|
@ -17,6 +17,12 @@ defmodule Ash.Type.Enum do
|
|||
end
|
||||
```
|
||||
|
||||
Then, you can rewrite your original attribute as follows:
|
||||
|
||||
```elixir
|
||||
attribute :status, MyApp.TicketStatus
|
||||
```
|
||||
|
||||
Valid values are:
|
||||
|
||||
* The atom itself, e.g `:open`
|
||||
|
|
Loading…
Reference in a new issue