How to move the content of a module which has no functions into a library?

In a Phoenix application I have this:

defmodule MyAppWeb.M1 do
    # [.......]
    if condition == true do
        plug(Plug.Static,
          at: a1,
          from: a2
        )

        plug(Plug.Static,
          at: a3,
          from: a4,
          gzip: false
        )

        # [........]
    end
end

defmodule MyAppWeb.Endpoint  do
    plug(MyAppWeb.M1)
end

Now I want to move this code into a library which I’ll use across multiple Phoenix projects. Given that there’re no functions in the module, how could it be done? By using a macro as the only one?

Macro solves your issue for sure. You can also try to implement custom plug where you compose two other plugs. Plug.Builder may be helpful here. Plug.Builder — Plug v1.11.1

1 Like