Attributes
Set and get complex attributes on modules
Installation
The package can be installed by adding attributes
to your list of dependencies in mix.exs
:
def deps do
[
{:attributes, "~> 0.1.1"}
]
end
Documentation
Documentation can be found at https://hexdocs.pm/attributes.
Usage
Attributes offers utility functions to set and get complex attributes on modules.
defmodule MyModule do
Attributes.set(__MODULE__, [:path, :to, :attr], :value)
end
Attributes supports nested maps and keyword. The previous assignment could be rewritten as follow:
Attributes.set(__MODULE__, [:path], [to: [attr: :value]])
Attributes.set(__MODULE__, [:path], %{to: %{attr: :value}})
After defining an attribute, you can obtain its value using Attributes.get/2
, Attributes.get/3
or Attributes.get!/2
methods.
iex> Attributes.get(MyModule, [:path, :to, :attr])
iex> :value
iex> Attributes.get(MyModule, [:path, :to])
iex> [attr: :value]