genserver for globally storing attributes
This code is available in Hex at (https://hex.pm/packages/attribute_server) and can be installed as:
- Add
attribute_server
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:attribute_server, "~> 0.1.0"}]
end
```
Use it in a module you want to track attributes in
defmodule MyApp.GameState do
...
use AttributeServer
...
end
set
# set some attributes
MyApp.GameState.set :current_score, 1000
MyApp.GameState.set :current_level, 3
get
# get some attributes
MyApp.GameState.get :current_score
MyApp.GameState.get :current_level
all
# retrieve all attributes
MyApp.GameState.all
clear
# clear all attributes
MyApp.GameState.clear
size
# get total number of attributes
MyApp.GameState.size