MaxoAdapt (maxo_adapt v0.1.12)

Copy Markdown View Source

Generates adapter facade functions from an Elixir behaviour.

Use MaxoAdapt in a module and declare required callbacks inside behaviour/1:

defmodule Storage do
  use MaxoAdapt, default: Storage.Memory

  behaviour do
    @callback get(binary()) :: {:ok, term()} | {:error, atom()}
  end
end

The resulting module is a normal behaviour and exposes each required callback, configure/1, and __maxo_adapt__/0. See the configuration guide for the :compile, :get_compiled, :get_env, and :get_dict dispatch modes.

Summary

Types

:app and :key.

Functions

Define the adapter behaviour through callbacks. A @doc tag can be set for each @callback.

Types

option()

@type option() ::
  {:app, atom()}
  | {:key, atom()}
  | {:default, module()}
  | {:error, atom()}
  | {:log, false | :debug | :info | :notice}
  | {:mode, :compile | :get_compiled | :get_env | :get_dict}
  | {:random, boolean()}
  | {:validate, boolean()}

:app and :key.

Functions

behaviour(list)

(macro)
@spec behaviour(callbacks :: [{:do, term()}]) :: term()

Define the adapter behaviour through callbacks. A @doc tag can be set for each @callback.

Each required callback becomes a callable facade function with the callback's documentation and spec.

Example

behaviour do
  @doc ~S"""
  Get session from storage.
  """
  @callback get(token :: binary) :: {:ok, Session.t | nil} | {:error, atom}
end