# Acessor
## Description
`acessor` is a library to make it easy to orchestrate multiple services while using Elixir processes.
## Installation
the package can be installed by adding `acessor` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:acessor, "~> 0.1.2"}
]
end
```
## Run tests
```sh
mix test
```
## Usage
```elixir
defmodule MyModule do
use Acessor.Macros.Service # using the macro registers the service and enables logger
def hello(name) do
"Hello, " <> name
end
end
defmodule MyModule2 do
use Acessor.Macros.Service # using the macro registers the service and enables logger
def bye(name, age) do
"Hello, " <> name " with age " <> age
end
end
services = %{:mymodule => MyModule, :byemodule => MyModule2}
Acessor.config(services) # true
Acessor.docs() # %{mymodule => [hello: 0], byemodule => [bye: 2]}
# [info] Module: mymodule - Functions: [hello: 0]
# [info] Module: byemodule - Functions: [bye: 2]
{:response, response} = Acessor.invoke(:mymodule, :hello, ["Bob"])
assert response == "Hello, Bob"
```
## Use Cases
`acessor` is useful when you have multiple services in your ecosystem, and you need to invoke them all the time. This could eliminate code duplication where all services could be centralized inside a library/repo for example:
```elixir
# this could be a new library/repo used across services
defmodule MyService1 do
def make_rest_request(_), do: :rest1
end
defmodule MyService2 do
def make_rest_request(_), do: :rest2
end
services = %{:service_1 => MyService1, :service_2 => MyService2}
Acessor.config(services)
Acessor.docs() # get access of the registered services docs
Acessor.invoke(:service_1, :make_rest_request, []) # {:response, :rest1}
Acessor.invoke(:service_2, :make_rest_request, []) # {:response, :rest2}
```
## Methods
`config/1 - services (inside %{})`
this method adds your services to the acessor, making it possible to invoke any methods after this initial setup.
`docs/0`
this method logs and returns all registerd services methods + arity inside a map
`invoke/3 - service_name, method, args (inside [])`
this method uses `GenServer` to invoke your registered service, returning:
`{:response, response}` or `{:noresponse, nil}`