Skip to content

Commit a309bd2

Browse files
committed
Reusable and extendable validator
1 parent 9067527 commit a309bd2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/jsonrpc2_plug/validator.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ defmodule JSONRPC2Plug.Validator do
99

1010
@type validator :: (Rule.value() -> Rule.result())
1111

12+
defmacro __using__(_) do
13+
:functions
14+
|> __MODULE__.__info__()
15+
|> Enum.map(fn({func, arity}) ->
16+
arguments = 0..10
17+
|> Enum.take(arity)
18+
|> Enum.map(&(:"arg#{&1}"))
19+
|> Enum.map(&Macro.var(&1, nil))
20+
21+
quote location: :keep do
22+
def unquote(func)(unquote_splicing(arguments)) do
23+
unquote(__MODULE__).unquote(func)(unquote_splicing(arguments))
24+
end
25+
end
26+
end)
27+
end
28+
1229
@spec required() :: validator()
1330
def required do
1431
fn(value) ->

0 commit comments

Comments
 (0)