Skip to content

Instantly share code, notes, and snippets.

@gabrielgatu
Last active June 22, 2017 10:37
Show Gist options
  • Save gabrielgatu/285b473f87b63f2417f997b34e2e9e3e to your computer and use it in GitHub Desktop.
Save gabrielgatu/285b473f87b63f2417f997b34e2e9e3e to your computer and use it in GitHub Desktop.
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