Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom attribute types #11

Open
amclain opened this issue Oct 26, 2024 · 0 comments
Open

Custom attribute types #11

amclain opened this issue Oct 26, 2024 · 0 comments
Labels

Comments

@amclain
Copy link
Member

amclain commented Oct 26, 2024

User Story

As a developer, I want to define custom attribute types for my project so that I can better represent our domain's concepts and reuse these types across my specs.

Acceptance Criteria

TBD

Engineering Notes

⚠️ WIP

Spec:

# attribute <name>, <type>
attribute :uuid, :uuid

Type module:

defmodule CustomTypes do
  def uuid(value, opts) do
    format = ~r/\A\d{5}\-\d{5}\-\d{5}\-\d{5}\-\d{5}\z/
    
    case Regex.match?(format, value) do
      true -> {:ok, value}
      _    -> {:error, :wrong_format}
    end
  end
end

Config:

config :speck, custom_types: [CustomTypes]
# or because of compiler order...
config :speck, custom_type_path: "protocol/_types"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant