Raxol.Core.Runtime.Plugins.StateManager (Raxol v0.3.0)
View SourceManages plugin state and state transitions.
Summary
Functions
Gets a plugin's configuration.
Gets a plugin's metadata.
Gets a plugin's module.
Gets a plugin's state.
Returns a new default plugin manager state struct.
Removes a plugin from the state maps.
Sets the state for a given plugin. Alias for update_plugin_state/3.
Updates a plugin's state.
Updates the plugin state maps with a new plugin.
Functions
Gets a plugin's configuration.
Parameters
plugin_id
- The ID of the pluginstate_maps
- Map containing all state maps
Returns
- The plugin's configuration, or nil if not found
Examples
iex> StateManager.get_plugin_config("my_plugin", %{
plugin_config: %{"my_plugin" => %{setting: "value"}}
})
%{setting: "value"}
Gets a plugin's metadata.
Parameters
plugin_id
- The ID of the pluginstate_maps
- Map containing all state maps
Returns
- The plugin's metadata, or nil if not found
Examples
iex> StateManager.get_plugin_metadata("my_plugin", %{
metadata: %{"my_plugin" => %{version: "1.0.0"}}
})
%{version: "1.0.0"}
Gets a plugin's module.
Parameters
plugin_id
- The ID of the pluginstate_maps
- Map containing all state maps
Returns
- The plugin's module, or nil if not found
Examples
iex> StateManager.get_plugin_module("my_plugin", %{
plugins: %{"my_plugin" => MyPlugin}
})
MyPlugin
Gets a plugin's state.
Parameters
plugin_id
- The ID of the pluginstate_maps
- Map containing all state maps
Returns
- The plugin's state, or nil if not found
Examples
iex> StateManager.get_plugin_state("my_plugin", %{
plugin_states: %{"my_plugin" => %{initialized: true}}
})
%{initialized: true}
Returns a new default plugin manager state struct.
Removes a plugin from the state maps.
Parameters
plugin_id
- The ID of the plugin to removestate_maps
- Map containing all state maps
Returns
- Updated state maps
Examples
iex> StateManager.remove_plugin("my_plugin", %{
plugins: %{"my_plugin" => MyPlugin},
metadata: %{"my_plugin" => %{version: "1.0.0"}},
plugin_states: %{"my_plugin" => %{initialized: true}},
load_order: ["my_plugin"],
plugin_config: %{"my_plugin" => %{setting: "value"}}
})
%{
plugins: %{},
metadata: %{},
plugin_states: %{},
load_order: [],
plugin_config: %{}
}
Sets the state for a given plugin. Alias for update_plugin_state/3.
Updates a plugin's state.
Parameters
plugin_id
- The ID of the pluginnew_state
- The new state to setstate_maps
- Map containing all state maps
Returns
- Updated state maps
Examples
iex> StateManager.update_plugin_state("my_plugin", %{updated: true}, %{
plugins: %{"my_plugin" => MyPlugin},
metadata: %{"my_plugin" => %{version: "1.0.0"}},
plugin_states: %{"my_plugin" => %{initialized: true}},
load_order: ["my_plugin"],
plugin_config: %{"my_plugin" => %{setting: "value"}}
})
%{
plugins: %{"my_plugin" => MyPlugin},
metadata: %{"my_plugin" => %{version: "1.0.0"}},
plugin_states: %{"my_plugin" => %{updated: true}},
load_order: ["my_plugin"],
plugin_config: %{"my_plugin" => %{setting: "value"}}
}
Updates the plugin state maps with a new plugin.
Parameters
plugin_id
- The ID of the pluginplugin_module
- The plugin's moduleplugin_metadata
- The plugin's metadataplugin_state
- The plugin's initial stateconfig
- The plugin's configurationstate_maps
- Map containing all state maps (plugins, metadata, states, load_order, config)
Returns
- Updated state maps
Examples
iex> StateManager.update_state_maps("my_plugin", MyPlugin, %{version: "1.0.0"}, %{initialized: true}, %{setting: "value"}, %{
plugins: %{},
metadata: %{},
plugin_states: %{},
load_order: [],
plugin_config: %{}
})
%{
plugins: %{"my_plugin" => MyPlugin},
metadata: %{"my_plugin" => %{version: "1.0.0"}},
plugin_states: %{"my_plugin" => %{initialized: true}},
load_order: ["my_plugin"],
plugin_config: %{"my_plugin" => %{setting: "value"}}
}