add typesecs and docstrings

This commit is contained in:
Your Name 2025-09-16 13:13:27 +00:00
parent 8112173ef4
commit 8b527f618a
2 changed files with 19 additions and 1 deletions

View File

@ -10,6 +10,7 @@ defmodule BasicSignupAllowlist do
@doc """
Returns the name of the environment variable used for the signup allowlist.
"""
@spec signup_allowlist_emails() :: String.t()
def signup_allowlist_emails, do: @signup_allowlist_emails
@doc """
@ -33,6 +34,7 @@ defmodule BasicSignupAllowlist do
true
"""
@spec signup_allowed?(String.t()) :: boolean()
def signup_allowed?(email) do
env_value = System.get_env(@signup_allowlist_emails)
signup_allowed_fun(env_value, email)

View File

@ -1,14 +1,30 @@
defmodule FunCore.BasicSignupAllowlist do
@moduledoc """
Functional core for email allowlist checking logic.
"""
@doc """
Normalizes an email address by trimming whitespace and converting to lowercase.
"""
@spec normalize(String.t()) :: String.t()
def normalize(email) do
email |> String.trim() |> String.downcase()
end
@doc """
Converts a comma-separated string of email addresses into a normalized list.
"""
@spec addresses_as_list(String.t()) :: [String.t()]
def addresses_as_list(addresses_str) do
addresses_str
|> String.split(",")
|> Enum.map(&normalize/1)
end
@doc """
Checks if an email is allowed based on the allowlist configuration.
"""
@spec signup_allowed_fun(String.t() | nil, String.t()) :: boolean()
def signup_allowed_fun(signups_allowed, email_received) do
case signups_allowed do
nil -> false