Reputation: 2333
So, I have mix project, with module Uploader.Server
and module Uploader.Utility
.
Uploader.Utility
defines request
macro. Problem is that I can't access it like this in Uploader.Server
, I can only call Uploader.Utility.request
, which is very inconvinient, as server module provides shell interface and request
is going to be a common argument for commands.
I can just put this macro in Uploader.Server
module, but logically it does not belong there.
Can I somehow provide access to this macro Uploader.Server
just by inner name, not outer, something like alias?
Upvotes: 1
Views: 168
Reputation: 222118
You're looking for Kernel.SpecialForms.import/2
.
Example:
defmodule Uploader.Utility do
defmacro request(name) do
quote do
def unquote(name)(), do: :ok
end
end
end
defmodule Uploader.Server do
require Uploader.Utility
import Uploader.Utility, only: [request: 1]
request(:hello)
end
IO.inspect Uploader.Server.hello
prints
:ok
Upvotes: 2