Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbf3a06
commit aaf2f00
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule JSONRPC.Method do | ||
defmacro __using__(_opts) do | ||
quote do | ||
import JSONRPC.Method | ||
end | ||
end | ||
|
||
defmacro defmethod(module_name, arg_name, opts, do: block) do | ||
pre = | ||
opts | ||
|> Keyword.get(:pre, []) | ||
|> List.wrap() | ||
|> Enum.map(fn | ||
{processor, popts} -> quote do: process(unquote(processor), unquote(popts)) | ||
processor -> quote do: process(unquote(processor)) | ||
end) | ||
|
||
post = | ||
opts | ||
|> Keyword.get(:post, []) | ||
|> List.wrap() | ||
|> Enum.map(fn | ||
{processor, popts} -> quote do: process(unquote(processor), unquote(popts)) | ||
processor -> quote do: process(unquote(processor)) | ||
end) | ||
|
||
quote do | ||
defmodule unquote(module_name) do | ||
use JSONRPC.ActionBuilder | ||
|
||
unquote(pre) | ||
method(unquote(arg_name), do: unquote(block)) | ||
unquote(post) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters