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,27 +1,30 @@
|
|||
defmodule Mv.Membership.Email do
|
||||
@constraints [
|
||||
match: ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/,
|
||||
trim?: true,
|
||||
min_length: 5,
|
||||
max_length: 254
|
||||
]
|
||||
@match_pattern ~S/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
|
||||
@match_regex Regex.compile!(@match_pattern)
|
||||
@min_length 5
|
||||
@max_length 254
|
||||
|
||||
use Ash.Type.NewType,
|
||||
subtype_of: :string,
|
||||
constraints: @constraints
|
||||
constraints: [
|
||||
match: @match_pattern,
|
||||
trim?: true,
|
||||
min_length: @min_length,
|
||||
max_length: @max_length
|
||||
]
|
||||
|
||||
@impl true
|
||||
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
|
||||
@constraints[:min_length] && String.length(value) < @constraints[:min_length] ->
|
||||
String.length(value) < @min_length ->
|
||||
:error
|
||||
|
||||
@constraints[:max_length] && String.length(value) > @constraints[:max_length] ->
|
||||
String.length(value) > @max_length ->
|
||||
:error
|
||||
|
||||
@constraints[:match] && !Regex.match?(@constraints[:match], value) ->
|
||||
!Regex.match?(@match_regex, value) ->
|
||||
:error
|
||||
|
||||
true ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue