I have a project which will be used as a template. I’ll then copy it and create a sub-project based on it. I want to be able to update it from the upstream without conflict.
All the *.ex
files that are specific to a sub-project won’t be in git. Therefore, they’ll have to be created manually and loaded dynamically.
Question: how to load external .ex
into the current one, to then compile it? Not at runtime, but at the compile-time.
This will be something similar to this:
# my_controller.ex
defmodule MyAppWeb.MyController do
use MyAppWeb, :controller
def page1(conn, params) do
# ........
end
# HOW to implement this function?
inject_external_file_if_exists("my_controller.personal.ex")
end
Code specific to a sub-project could look like this:
# my_controller.personal.ex
defmodule MyAppWeb.MyController do
use MyAppWeb, :controller
def specific_page1(conn, params) do
# ........
end
def specific_page2(conn, params) do
# ........
end
end
Note that my_controller.personal.ex
contains the definition of MyAppWeb.MyController
once again. This isn’t a strict requirement. The idea is to merge at compile them rather than overwrite each other.