Skip to content

Commit

Permalink
add doc for validate!/1 and validate/1
Browse files Browse the repository at this point in the history
  • Loading branch information
vacarsu committed Dec 14, 2021
1 parent d4cb559 commit b07e4d3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/scenic/themes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ defmodule Scenic.Themes do
end
end

@doc """
Validates a theme, raises when an invalid themes is passed in.
"""
def validate!(theme)
def validate!({lib, theme_name} = lib_theme) when is_atom(theme_name) do
themes = module().library()
Expand Down Expand Up @@ -256,6 +259,9 @@ defmodule Scenic.Themes do
end)
end

@doc """
Validates a theme, returns `{:ok, theme}` on a valid theme or `{:error, :error_type}` on an invalid theme.
"""
def validate(theme)
def validate({lib, theme_name} = lib_theme) when is_atom(theme_name) do
themes = module().library()
Expand Down Expand Up @@ -318,22 +324,22 @@ defmodule Scenic.Themes do
_, {:error, msg} ->
{:error, msg}

{key, color}, {:ok, _} = acc ->
{_key, color}, {:ok, _} = acc ->
case Color.validate(color) do
{:ok, _} -> acc
{:error, msg} -> {:error, :invalid_color}
{:error, _msg} -> {:error, :invalid_color}
end
end)
end

def validate(%{} = map) do
def validate(%{} = _map) do
{
:error,
:missing_key
}
end

def validate(data) do
def validate(_data) do
{
:error,
:invalid
Expand Down

0 comments on commit b07e4d3

Please sign in to comment.