Raxol.Core.Runtime.Plugins.Loader (Raxol v0.3.0)

View Source

Handles 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

behaviour_implemented?(module, behaviour)

Checks if a module implements a specific behaviour.

Parameters

  • module - The module to check
  • behaviour - The behaviour to check for

Returns

  • true if the module implements the behaviour, false otherwise

Examples

iex> Loader.behaviour_implemented?(MyPlugin, Plugin)
true

extract_metadata(plugin_module)

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: []}

initialize_plugin(module, config)

Initializes a plugin with the given configuration.

Parameters

  • module - The plugin module to initialize
  • config - 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}}

load_code(plugin_module)

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

load_plugin(plugin_id, config \\ %{})

@spec load_plugin(atom(), map()) :: {:ok, module(), map(), map()} | {:error, term()}

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.

module_to_default_id(plugin_module)

Helper to derive a default plugin ID from the module name. Example: MyOrg.MyPlugin becomes :my_plugin.

sort_plugins(plugin_list)

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}.