Raxol.Core.Runtime.Plugins.Loader (Raxol v0.3.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 (Placeholder - consider for removal or refactor).
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 (Placeholder - consider for removal or refactor).
Currently returns the input list unsorted.
Requires metadata extraction to be implemented first for actual sorting.
Returns {:ok, sorted_plugin_ids}
or {:error, reason}
.