chore: fix deprication warnings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
712fbb14fa
commit
aa62920c0d
2 changed files with 16 additions and 14 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
version: "3.5"
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: postgres:17.2-alpine
|
image: postgres:17.2-alpine
|
||||||
|
|
@ -22,4 +20,5 @@ networks:
|
||||||
local:
|
local:
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres-data:
|
postgres-data:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,30 @@
|
||||||
defmodule Mv.Membership.Email do
|
defmodule Mv.Membership.Email do
|
||||||
@constraints [
|
@match_pattern ~S/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
|
||||||
match: ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/,
|
@match_regex Regex.compile!(@match_pattern)
|
||||||
trim?: true,
|
@min_length 5
|
||||||
min_length: 5,
|
@max_length 254
|
||||||
max_length: 254
|
|
||||||
]
|
|
||||||
|
|
||||||
use Ash.Type.NewType,
|
use Ash.Type.NewType,
|
||||||
subtype_of: :string,
|
subtype_of: :string,
|
||||||
constraints: @constraints
|
constraints: [
|
||||||
|
match: @match_pattern,
|
||||||
|
trim?: true,
|
||||||
|
min_length: @min_length,
|
||||||
|
max_length: @max_length
|
||||||
|
]
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def cast_input(value, _) when is_binary(value) do
|
def cast_input(value, _) when is_binary(value) do
|
||||||
value = if @constraints[:trim?], do: String.trim(value), else: value
|
value = String.trim(value)
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
@constraints[:min_length] && String.length(value) < @constraints[:min_length] ->
|
String.length(value) < @min_length ->
|
||||||
:error
|
:error
|
||||||
|
|
||||||
@constraints[:max_length] && String.length(value) > @constraints[:max_length] ->
|
String.length(value) > @max_length ->
|
||||||
:error
|
:error
|
||||||
|
|
||||||
@constraints[:match] && !Regex.match?(@constraints[:match], value) ->
|
!Regex.match?(@match_regex, value) ->
|
||||||
:error
|
:error
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue