Skip to content

Instantly share code, notes, and snippets.

@olivermt
Last active September 23, 2015 15:14
Show Gist options
  • Save olivermt/b29e42e2cc537e9bf7f2 to your computer and use it in GitHub Desktop.
Save olivermt/b29e42e2cc537e9bf7f2 to your computer and use it in GitHub Desktop.
#usage: use YourApp.CatchallController in web.ex right after use Phoenix.Controller
defmodule YourApp.CatchAllController do
defmacro __using__(_opts) do
quote do
@before_compile unquote(__MODULE__)
end
end
defmacro __before_compile__(env) do
actions = Module.definitions_in(env.module, :def)
#The following list might need to be updated if Phoenix.Controller adds more functions to your module in the future.
|> Keyword.drop([:action, :call, :init, :phoenix_controller_pipeline])
|> Enum.into(HashSet.new, fn({fun, _arity}) -> fun end)
for action <- actions do
quote do
def unquote(action)(conn, _params) do
Plug.Conn.send_resp(conn, 400, "")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment