Search documentation of Metastatic

# Metastatic.Analysis.Registry (Metastatic v0.13.2)

View Source

Registry for analyzer plugins.

Manages registration, discovery, and configuration of analyzers. Runs as a GenServer under the application supervision tree.

## Usage

    # Register an analyzer
    Registry.register(MyApp.Analysis.UnusedVariables)

    # Look up by name
    Registry.get_by_name(:unused_variables)

    # Look up by category
    Registry.list_by_category(:correctness)

    # List all
    Registry.list_all()

    # Configure analyzer
    Registry.configure(MyAnalyzer, %{threshold: 10})

## Configuration

Auto-register analyzers at application startup:

    # config/config.exs
    config :metastatic, :analyzers,
      auto_register: [
        Metastatic.Analysis.UnusedVariables,
        Metastatic.Analysis.SimplifyConditional
      ],
      disabled: [:some_analyzer],
      config: %{
        unused_variables: %{ignore_prefix: "_"}
      }

## Summary

### Types

registry_state()

### Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

clear()

Clears all registered analyzers.

configure(analyzer, config)

Updates configuration for an analyzer.

get_by_name(name)

Gets analyzer by name.

get_config(analyzer)

Gets configuration for an analyzer.

list_all()

Lists all registered analyzers.

list_by_category(category)

Lists analyzers by category.

list_categories()

Lists all available categories.

register(analyzer)

Registers an analyzer module.

start_link(opts \\ [])

Starts the registry GenServer.

unregister(analyzer)

Unregisters an analyzer module.

## Types

# registry_state()

    @type registry_state() :: %{
      by_name: %{required(atom()) => module()},
      by_category: %{required(atom()) => [module()]},
      all: MapSet.t(module()),
      config: %{required(module()) => map()}
    }

## Functions

# child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# clear()

    @spec clear() :: :ok

Clears all registered analyzers.

Primarily for testing purposes.

# configure(analyzer, config)

    @spec configure(module(), map()) :: :ok

Updates configuration for an analyzer.

Merges the new config with existing config.

## Examples

    iex> Registry.configure(MyAnalyzer, %{threshold: 10})
    :ok

# get_by_name(name)

    @spec get_by_name(atom()) :: module() | nil

Gets analyzer by name.

Returns `nil` if no analyzer is registered with that name.

## Examples

    iex> Registry.get_by_name(:unused_variables)
    MyApp.Analysis.UnusedVariables

    iex> Registry.get_by_name(:nonexistent)
    nil

# get_config(analyzer)

    @spec get_config(module()) :: map()

Gets configuration for an analyzer.

Returns empty map if no configuration is set.

## Examples

    iex> Registry.get_config(MyAnalyzer)
    %{threshold: 10}

# list_all()

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

Lists all registered analyzers.

## Examples

    iex> Registry.list_all()
    [MyApp.Analysis.UnusedVariables, MyApp.Analysis.SimplifyConditional]

# list_by_category(category)

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

Lists analyzers by category.

## Examples

    iex> Registry.list_by_category(:correctness)
    [MyApp.Analysis.UnusedVariables, MyApp.Analysis.DeadCode]

# list_categories()

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

Lists all available categories.

## Examples

    iex> Registry.list_categories()
    [:correctness, :style, :refactoring, :maintainability]

# register(analyzer)

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

Registers an analyzer module.

The module must implement the `Metastatic.Analysis.Analyzer` behaviour. Validates that no conflicts exist (another analyzer with same name).

## Examples

    iex> Registry.register(MyApp.Analysis.UnusedVariables)
    :ok

    iex> Registry.register(ConflictingAnalyzer)
    {:error, "Analyzer named :unused_variables already registered: ..."}

# start_link(opts \\ [])

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

Starts the registry GenServer.

Called automatically by the application supervision tree.

# unregister(analyzer)

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

Unregisters an analyzer module.

Removes the analyzer from the registry.

## Examples

    iex> Registry.unregister(MyApp.Analysis.UnusedVariables)
    :ok