Last active
June 22, 2017 10:37
-
-
Save gabrielgatu/285b473f87b63f2417f997b34e2e9e3e to your computer and use it in GitHub Desktop.
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
defmodule Mozzie.Service.DSL do | |
... | |
defmacro action(p1, p2, p3, do: block) do | |
p1 = to_list(p1) | |
p2 = to_list(p2) | |
quote do | |
def handle_action(unquote(p1), unquote(p2), unquote(p3)) do | |
case unquote(block) do | |
{:ok, val} -> {:ok, val} | |
{:error, val} -> {:error, val} | |
_ -> :ok | |
end | |
end | |
end | |
end | |
end | |
defmodule Mozzie.Service.Spotify do | |
use Mozzie.Service.DSL | |
action("start", "song", _opts), do: play_song() # This doesn't work | |
action("start", "song", _opts) do # This works | |
play_song() | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment