Metastatic.Supplemental.Registry (Metastatic v0.10.4)

View Source

Registry for supplemental modules.

Manages registration and lookup of supplemental modules that extend language adapter capabilities. Runs as a GenServer under the application supervision tree.

Usage

# Register a supplemental module
Registry.register(MyApp.Supplemental.Python.Pykka)

# Look up by language
Registry.list_for_language(:python)

# Look up by construct
Registry.get_for_construct(:python, :actor_call)

# List all available constructs for a language
Registry.available_constructs(:python)

Configuration

Auto-register supplementals at application startup:

# config/config.exs
config :metastatic, :supplementals,
  auto_register: [Metastatic.Supplemental.Python.Pykka],
  disabled: [:some_supplemental]

Summary

Functions

Lists all constructs that have supplemental support for a language.

Returns a specification to start this module under a supervisor.

Clears all registered supplementals.

Gets the supplemental module that handles a specific construct for a language.

Lists all registered supplemental modules.

Lists all supplemental modules registered for a language.

Registers a supplemental module.

Starts the registry GenServer.

Unregisters a supplemental module.

Types

construct_key()

@type construct_key() :: {language :: atom(), construct :: atom()}

registry_state()

@type registry_state() :: %{
  by_construct: %{required(construct_key()) => module()},
  by_language: %{required(atom()) => [module()]},
  all: MapSet.t(module())
}

Functions

available_constructs(language)

@spec available_constructs(atom()) :: [atom()]

Lists all constructs that have supplemental support for a language.

Examples

iex> Registry.available_constructs(:python)
[:actor_call, :actor_cast, :spawn_actor]

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Clears all registered supplementals.

Primarily for testing purposes.

get_for_construct(language, construct)

@spec get_for_construct(atom(), atom()) :: module() | nil

Gets the supplemental module that handles a specific construct for a language.

Returns nil if no supplemental is registered.

Examples

iex> Registry.get_for_construct(:python, :actor_call)
MyApp.Supplemental.Python.Pykka

iex> Registry.get_for_construct(:python, :unsupported_construct)
nil

list_all()

@spec list_all() :: [module()]

Lists all registered supplemental modules.

Examples

iex> Registry.list_all()
[MyApp.Supplemental.Python.Pykka]

list_for_language(language)

@spec list_for_language(atom()) :: [module()]

Lists all supplemental modules registered for a language.

Examples

iex> Registry.list_for_language(:python)
[MyApp.Supplemental.Python.Pykka, MyApp.Supplemental.Python.Asyncio]

register(module)

@spec register(module()) :: :ok | {:error, Exception.t()}

Registers a supplemental module.

The module must implement the Metastatic.Supplemental behaviour. Validates that no conflicts exist (another supplemental already handles the same constructs for the same language).

Examples

iex> Registry.register(MyApp.Supplemental.Python.Pykka)
:ok

iex> Registry.register(ConflictingModule)
{:error, %ConflictError{}}

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the registry GenServer.

Called automatically by the application supervision tree.

unregister(module)

@spec unregister(module()) :: :ok

Unregisters a supplemental module.

Removes the module from the registry.

Examples

iex> Registry.unregister(MyApp.Supplemental.Python.Pykka)
:ok