https://github.com/danielefongo/attributes
Set and get complex attributes on modules
https://github.com/danielefongo/attributes
attributes complex elixir macro
Last synced: 11 months ago
JSON representation
Set and get complex attributes on modules
- Host: GitHub
- URL: https://github.com/danielefongo/attributes
- Owner: danielefongo
- License: gpl-3.0
- Created: 2021-05-31T12:13:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-11T11:46:15.000Z (over 4 years ago)
- Last Synced: 2025-02-03T13:45:49.338Z (12 months ago)
- Topics: attributes, complex, elixir, macro
- Language: Elixir
- Homepage:
- Size: 48.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Attributes


[](https://hex.pm/packages/attributes)

Manipulate complex attributes on modules.
## Installation
The package can be installed by adding `attributes` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:attributes, "~> 0.4.0"}
]
end
```
## Documentation
Full documentation can be found at [https://hexdocs.pm/attributes](https://hexdocs.pm/attributes).
## Usage
Attributes offers utility functions to manipulate complex attributes on modules.
A typical usage could be inside macros that need to enrich modules before their compilation.
You can set, get, update or delete attributes' tree.
```elixir
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:
```elixir
Attributes.set(__MODULE__, [:path], [to: [attr: :value]])
```
```elixir
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.
```elixir
iex> Attributes.get(MyModule, [:path, :to, :attr])
iex> :value
```
```elixir
iex> Attributes.get(MyModule, [:path, :to])
iex> [attr: :value]
```