Skip to content

Custom attribute types #11

@amclain

Description

@amclain

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions