Skip to content

Commit

Permalink
fix: small fixes/cleanups for optiosn validations
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Aug 13, 2024
1 parent b0fd239 commit 1903e3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/spark/options/options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,19 @@ defmodule Spark.Options do
else
{:cont, {:ok, [{key, value} | validated], new_required}}
end
else
other ->
{:halt, other}
end
end)
|> case do
{:ok, validated, []} ->
case defaults do
[] ->
{:ok, validated}
{:ok, Enum.reverse(validated)}

_ ->
{:ok, Keyword.merge(defaults, validated)}
{:ok, Enum.reverse(Keyword.merge(defaults, validated))}
end

{:ok, _validated, [key | _]} ->
Expand Down Expand Up @@ -797,7 +800,7 @@ defmodule Spark.Options do
end

@doc false
def validate_single_type(type, key, value) do
def validate_single_value(type, key, value) do
validate_type(type, key, value)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/spark/options/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ defmodule Spark.Options.Validator do
def validate_option(unquote(key), value, {acc, required_fields}) do
case Spark.Options.validate_single_value(unquote(type), unquote(key), value) do
{:ok, value} ->
{:cont, %{acc | unquote(key) => value},
use_key(required_fields, unquote(key))}
{:cont, {%{acc | unquote(key) => value},
use_key(required_fields, unquote(key))}}

{:error, error} ->
{:halt, {:error, error}}
Expand Down

0 comments on commit 1903e3f

Please sign in to comment.