Skip to content

Commit

Permalink
Add JSONRPC.Method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpeachey committed Mar 21, 2019
1 parent cbf3a06 commit aaf2f00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions lib/json_rpc/method.ex
@@ -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
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -4,7 +4,7 @@ defmodule JsonRpcToolkit.MixProject do
def project do
[
app: :json_rpc_toolkit,
version: "0.9.1",
version: "0.9.2",
name: "json_rpc_toolkit",
description: "A transport agnostic JSON-RPC library with support for Phoenix",
elixir: "~> 1.8",
Expand Down

0 comments on commit aaf2f00

Please sign in to comment.