Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit af6e913

Browse files
authored
Merge pull request #290 from coderplanets/editor-validator
chore(editor-validator): fmt code && clean up
2 parents a07bdfb + d6b2c47 commit af6e913

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

lib/helper/validator/schema.ex

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ defmodule Helper.Validator.Schema do
4949
end)
5050
end
5151

52-
defp match(field, nil, enum: _, required: false), do: done(field, nil)
52+
defp option_valid?({:min, v}) when is_integer(v), do: true
53+
defp option_valid?({:required, v}) when is_boolean(v), do: true
54+
defp option_valid?(_), do: false
5355

54-
defp match(field, value, enum: enum, required: _) do
55-
match(field, value, enum: enum)
56-
end
56+
defp match(field, nil, enum: _, required: false), do: done(field, nil)
57+
defp match(field, value, enum: enum, required: _), do: match(field, value, enum: enum)
5758

5859
defp match(field, value, enum: enum) do
5960
case value in enum do
@@ -69,13 +70,8 @@ defmodule Helper.Validator.Schema do
6970
end
7071
end
7172

72-
defp match(field, value, [type | options]) do
73-
match(field, value, type, options)
74-
end
75-
76-
defp match(field, nil, _type, [{:required, false} | _options]) do
77-
done(field, nil)
78-
end
73+
defp match(field, value, [type | options]), do: match(field, value, type, options)
74+
defp match(field, nil, _type, [{:required, false} | _options]), do: done(field, nil)
7975

8076
defp match(field, value, type, [{:required, _} | options]) do
8177
match(field, value, type, options)
@@ -138,15 +134,7 @@ defmodule Helper.Validator.Schema do
138134
{:error, %{field: field |> to_string, value: value, message: "unknow option: #{option}"}}
139135
end
140136

141-
defp error(field, value, :option) do
142-
{:error, %{field: field |> to_string, value: value, message: "unknow option"}}
143-
end
144-
145137
defp error(field, value, schema) do
146138
{:error, %{field: field |> to_string, value: value, message: "should be: #{schema}"}}
147139
end
148-
149-
defp option_valid?({:min, v}) when is_integer(v), do: true
150-
defp option_valid?({:required, v}) when is_boolean(v), do: true
151-
defp option_valid?(_), do: false
152140
end

test/helper/validator/schema_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do
8585
# hello world
8686
end
8787

88+
@tag :wip2
8889
test "number with wrong option" do
8990
schema = %{"text" => [:number, required: true, min: "5"]}
9091
data = %{"text" => 1}

0 commit comments

Comments
 (0)