Search documentation of Metastatic

# Metastatic.Supplemental.Registry (Metastatic v0.2.0)

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

## Types

construct_key()
registry_state()

## Functions

available_constructs(language)

Lists all constructs that have supplemental support for a language.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

clear()

Clears all registered supplementals.

get_for_construct(language, construct)

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

list_all()

Lists all registered supplemental modules.

list_for_language(language)

Lists all supplemental modules registered for a language.

register(module)

Registers a supplemental module.

start_link(opts \\ [])

Starts the registry GenServer.

unregister(module)

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