Raxol.Core.Runtime.Plugins.Loader (Raxol v0.4.0)
View SourceHandles loading plugin code, metadata, and discovery.
Implements the Raxol.Core.Runtime.Plugins.LoaderBehaviour
.
Summary
Functions
Checks if a module implements a specific behaviour.
Extracts metadata from a plugin module.
Initializes a plugin with the given configuration.
Loads a plugin module's code.
Loads a plugin module based on its ID (Original function - consider for removal or refactor).
Helper to derive a default plugin ID from the module name.
Example: MyOrg.MyPlugin
becomes :my_plugin
.
Sorts plugins based on dependencies.
Functions
Checks if a module implements a specific behaviour.
Parameters
module
- The module to checkbehaviour
- The behaviour to check for
Returns
true
if the module implements the behaviour,false
otherwise
Examples
iex> Loader.behaviour_implemented?(MyPlugin, Plugin)
true
Extracts metadata from a plugin module.
Parameters
module
- The module to extract metadata from
Returns
- A map containing the plugin's metadata
Examples
iex> Loader.extract_metadata(MyPlugin)
%{id: "my_plugin", version: "1.0.0", dependencies: []}
Initializes a plugin with the given configuration.
Parameters
module
- The plugin module to initializeconfig
- The configuration to pass to the plugin's init/1 callback
Returns
{:ok, state}
- If initialization was successful{:error, reason}
- If initialization failed
Examples
iex> Loader.initialize_plugin(MyPlugin, %{setting: "value"})
{:ok, %{initialized: true}}
Loads a plugin module's code.
Parameters
module
- The module to load
Returns
:ok
- If the module was loaded successfully{:error, :module_not_found}
- If the module could not be found
Examples
iex> Loader.load_code(MyPlugin)
:ok
Loads a plugin module based on its ID (Original function - consider for removal or refactor).
Assumes the plugin ID corresponds to an existing module atom. Returns the module atom, placeholder metadata, and config.
Helper to derive a default plugin ID from the module name.
Example: MyOrg.MyPlugin
becomes :my_plugin
.
Sorts plugins based on dependencies.
Takes a list of plugin structures (e.g., Raxol.Core.Runtime.Plugins.Plugin.t()
),
each containing at least an :id
and a :dependencies
field.
The :dependencies
field is expected to be a list of {dependency_id, version_requirement}
tuples.
Returns {:ok, sorted_plugin_ids}
in topological order, or
{:error, :cycle_detected, problematic_ids}
if a cycle is found,
or {:error, :missing_dependency, %{plugin_id: id, missing_dep_id: dep_id}}
if a declared dependency is not found within the input plugin list.