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 """ @doc """
Returns the name of the environment variable used for the signup allowlist. 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 def signup_allowlist_emails, do: @signup_allowlist_emails
@doc """ @doc """
@ -28,11 +29,12 @@ defmodule BasicSignupAllowlist do
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS") iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
false false
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*") iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*")
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
true true
""" """
@spec signup_allowed?(String.t()) :: boolean()
def signup_allowed?(email) do def signup_allowed?(email) do
env_value = System.get_env(@signup_allowlist_emails) env_value = System.get_env(@signup_allowlist_emails)
signup_allowed_fun(env_value, email) signup_allowed_fun(env_value, email)

View File

@ -1,14 +1,30 @@
defmodule FunCore.BasicSignupAllowlist do 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 def normalize(email) do
email |> String.trim() |> String.downcase() email |> String.trim() |> String.downcase()
end 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 def addresses_as_list(addresses_str) do
addresses_str addresses_str
|> String.split(",") |> String.split(",")
|> Enum.map(&normalize/1) |> Enum.map(&normalize/1)
end 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 def signup_allowed_fun(signups_allowed, email_received) do
case signups_allowed do case signups_allowed do
nil -> false nil -> false