From aa62920c0d8b6802d4636d9885e82004f988e216 Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 2 Jun 2025 14:42:48 +0200 Subject: [PATCH] chore: fix deprication warnings --- docker-compose.yml | 5 ++--- lib/membership/email.ex | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0ac02ca..28bc849 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.5" - services: db: image: postgres:17.2-alpine @@ -22,4 +20,5 @@ networks: local: volumes: - postgres-data: \ No newline at end of file + postgres-data: + diff --git a/lib/membership/email.ex b/lib/membership/email.ex index eacd548..c611742 100644 --- a/lib/membership/email.ex +++ b/lib/membership/email.ex @@ -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 ->