Building the controller DSL
To successfully call the use Goldcrest.Controller
statement, we will need to define a __using__/1
macro in Goldcrest.Controller
, which is responsible for injecting a controller-like behavior into a module.
Let’s start by simply moving the Plug.Builder
call, the Plug.Conn
call, and the call/2
function to the Goldcrest.Controller.__using__/1
macro:
defmodule Goldcrest.Controller do import Plug.Conn defmacro __using__(_) do quote do use Plug.Builder import Plug.Conn def call(conn, action: action) do conn = super(conn, []) apply(__MODULE__, action, [conn, conn.params]) end end end # .. end
In the previous code snippet...