Ash FrameworkAF
Ash Framework3y ago
12 replies
\ ឵឵឵

Using `Ash.Type.String` like `Ash.Type.Enum`

What I'm imagining:

lib/bookstore/types/isbn.ex:
defmodule Bookstore.Type.ISBN do
  use Ash.String, match: ~r/((978[\--– ])?[0-9][0-9\--– ]{10}[\--– ][0-9xX])|((978)?[0-9]{9}[0-9Xx])/
end


lib/bookstore/resources/book.ex:
defmodule Bookstore.Book do
  alias Bookstore.Type
  attributes do
    attribute :isbn, ISBN
  end
end


Seems like it would be good to be able to reuse and narrow many of the core types this way. Thoughts?
Was this page helpful?