On the library side, you can specify functions and macros that the caller can use by default.
defmodule MyModule do
use Exporter, default: [a: 0, b: 1]
def a, do: "a"
def b(_), do: "b"
def c, do: "c"
end
defmodule MyApp do
use MyModule
a() # ok. default import
b(1) # ok. default import
c() # error
use MyModule, [c: 0]
a() # error
b(1) # error
c() # ok
end
# allow override
defmodule MyModule do
use Exporter, default: [a: 0, b: 1]
defmacro __using__(opt) do
ast = super(opt)
quote do
import Enum, only: [min: 1]
unquote(ast)
end
end
end
If available in Hex, the package can be installed
by adding exporter
to your list of dependencies in mix.exs
:
def deps do
[{:exporter, "~> 0.1.0"}]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exporter.