Mixin for Elixir
It allows you to do mixin like in Ruby. For example:
I have an apple:
defmodule Apple do
use Mixeur
def apple do
"Apple"
end
end
I have a pen:
defmodule Pen do
use Mixeur
def pen do
"Pen"
end
end
Oh Oh Oh ApplePen:
defmodule ApplePen do
use Apple
use Pen
def apple_pen do
"#{apple()}#{pen()}"
end
end
Mixeur
basically leverages defdelegate
macro in Elixir
. So not only it allows
you to call functions inside a module(this behaviour is like import
), also it exposes those functions
to the outside world. For the example above, you can do:
iex> ApplePen.apple
"apple"
iex> ApplePen.pen
"pen"
If available in Hex, the package can be installed
by adding mixeur
to your list of dependencies in mix.exs
:
def deps do
[
{:mixeur, "~> 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/mixeur.