-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathaddress.ex
More file actions
40 lines (32 loc) · 758 Bytes
/
address.ex
File metadata and controls
40 lines (32 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
defmodule Fields.Address do
@moduledoc """
An Ecto Type for plaintext addresses.
Useful for publicly available addressses.
See `Fields.AddressEncrypted` for storing addresses
that are Personally Identifiable Information.
## Example
```
schema "retailers" do
field :address, Fields.Address
end
```
"""
alias Fields.Validate
use Ecto.Type
def type, do: :string
def cast(value) do
value = value |> to_string() |> String.trim()
case Validate.address(value) do
true -> {:ok, value}
false -> :error
end
end
def dump(value) do
{:ok, to_string(value)}
end
def load(value) do
{:ok, value}
end
def embed_as(_), do: :self
def equal?(term1, term2), do: term1 == term2
end