I have a general-purpose loader for fetching records from a database:
defmodule Loader do
defmacro __using__(opts) do
quote location: :keep, bind_quoted: [schema: opts[:schema]] do
def one(id), do: unquote(schema) |> Repo.get(id)
def all, do: unquote(schema) |> Repo.all
end
end
end
and particular loaders fro specific schemas:
defmodule Location.Loader do
use Loader, schema: Location
end
Is there any way to communicate with "used" module in some other way e.g. __MODULE__.parent?
LoadertoLocationwhich is a "top" module of a module whereLoaderis used.Loader. What do you mean by "access" - call functions? If so you can call public functions withLoader.some_function(). There is no way to call private functions from another module.Location.Loader.allorLocation.Loader.one(123). The thing is that I want to know somehow in generalLoader, the name of module it is invoked from e.g.Location.Loader. I achieved that by passing this inoptsbut i wonder if there's any other way to do so.