nova_plugin_manager (nova v0.14.3)

View Source

Main manager for handling plugins

Summary

Functions

Adds a plugin to the manager. The plugin module must implement the plugin_info/0 function returning #{title := Title, version := Version}. Optionally it can implement init/0 returning the initial state for the plugin, and stop/0 for cleaning up when the manager terminates.

Gets the state of a plugin. The plugin can be specified either as a module or as a callback function. The callback function is used to extract the module name in order to retrieve the state.

Sets the state of a plugin. The plugin can be specified either as a module or as a callback function. The callback function is used to extract the module name in order to set the state.

Starts the server

Functions

add_plugin(Module)

-spec add_plugin({Class :: atom(), Module :: atom(), Opts :: map()} |
                 (Module :: atom() | (Callback :: function()))) ->
                    ok | {error, Reason :: term()}.

Adds a plugin to the manager. The plugin module must implement the plugin_info/0 function returning #{title := Title, version := Version}. Optionally it can implement init/0 returning the initial state for the plugin, and stop/0 for cleaning up when the manager terminates.

add_plugin(Module, Name, Version)

-spec add_plugin(Module :: atom(), Name :: binary(), Version :: binary()) ->
                    ok | {error, Reason :: term()}.

get_state(Module)

-spec get_state(Module :: atom() | (Callback :: function())) ->
                   {ok, State :: nova:state()} | {error, not_found}.

Gets the state of a plugin. The plugin can be specified either as a module or as a callback function. The callback function is used to extract the module name in order to retrieve the state.

set_state(Module, NewState)

-spec set_state(Module :: atom() | (Callback :: function()), NewState :: term()) ->
                   ok | {error, not_found}.

Sets the state of a plugin. The plugin can be specified either as a module or as a callback function. The callback function is used to extract the module name in order to set the state.

start_link()

-spec start_link() ->
                    {ok, Pid :: pid()} |
                    {error, Error :: {already_started, pid()}} |
                    {error, Error :: term()} |
                    ignore.

Starts the server