Metastatic.Adapter.Registry
(Metastatic v0.8.4)
View Source
Registry for language adapters.
Provides a centralized registry for managing language adapters that implement
the Metastatic.Adapter behaviour. Adapters can be registered dynamically
or discovered automatically from the application.
Meta-Modeling Context
The registry maintains mappings between:
- Languages (atoms like
:python,:javascript) → Adapter modules - File extensions (strings like
".py") → Languages
This enables automatic language detection and adapter selection for M1 ↔ M2 transformations.
Usage
# Register an adapter
Registry.register(:python, Metastatic.Adapters.Python)
# Get adapter for a language
{:ok, adapter} = Registry.get(:python)
# Detect language from filename
{:ok, language} = Registry.detect_language("script.py")
# List all registered adapters
adapters = Registry.list()
Summary
Functions
Returns a specification to start this module under a supervisor.
Detect language from filename based on extension.
Get the adapter module for a language.
List all registered adapters.
Register a language adapter.
Check if a language is registered.
Start the registry.
Unregister a language adapter.
Validate that all registered adapters are still valid.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Detect language from filename based on extension.
Uses the registered adapters' file extensions to determine the language.
Examples
iex> Registry.detect_language("script.py")
{:ok, :python}
iex> Registry.detect_language("app.js")
{:ok, :javascript}
iex> Registry.detect_language("unknown.xyz")
{:error, :unknown_extension}
Get the adapter module for a language.
Examples
iex> Registry.get(:python)
{:ok, Metastatic.Adapters.Python}
iex> Registry.get(:unknown)
{:error, :not_found}
List all registered adapters.
Returns a map of language atoms to adapter modules.
Examples
iex> Registry.list()
%{python: Metastatic.Adapters.Python, javascript: Metastatic.Adapters.JavaScript}
Register a language adapter.
Parameters
language- Language identifier (e.g.,:python,:javascript)adapter- Module implementingMetastatic.Adapterbehaviour
Examples
iex> Registry.register(:python, Metastatic.Adapters.Python)
:ok
iex> Registry.register(:python, InvalidModule)
{:error, :invalid_adapter}
Check if a language is registered.
Examples
iex> Registry.registered?(:python)
true
iex> Registry.registered?(:unknown)
false
@spec start_link(keyword()) :: GenServer.on_start()
Start the registry.
This is typically called by the application supervisor.
@spec unregister(atom()) :: :ok
Unregister a language adapter.
Examples
iex> Registry.unregister(:python)
:ok
Validate that all registered adapters are still valid.
Returns a list of invalid adapters (if any).
Examples
iex> Registry.validate_all()
{:ok, []}
iex> Registry.validate_all()
{:error, [python: "Missing required callback: parse/1"]}