Minga.Command.Registry (Minga v0.1.0)

Copy Markdown View Source

ETS-backed registry for named editor commands.

Commands are stored by name (atom) in an ETS table with read_concurrency: true for lock-free lookups on the hot path. A companion ETS table stores the source that contributed each command so config reloads and extension unloads can remove everything owned by one source without touching other contributions.

Sources

A command can be owned by :builtin, :config, or {:extension, name}. Registering the same command name from the same source replaces that source's previous value. Registering a duplicate name from a different source is rejected deterministically.

Built-in command providers are seeded through the same source-owned registration path used by config and extensions.

Summary

Types

Source that contributed registry entries.

Command registration failure reason.

Registry server name or pid. Used as the ETS table name.

Functions

Returns all registered commands as a list.

Returns a specification to start this module under a supervisor.

Looks up a command by name.

Registers a config-owned command with the given name, description, and execute function.

Registers a command with an explicit source.

Registers a config-owned pre-built %Command{} struct.

Registers a pre-built %Command{} struct with an explicit source.

Registers multiple commands for one source as a group.

Registers every command returned by a provider module for one source.

Resets the registry to built-in commands only.

Starts the command registry as a named GenServer that owns ETS tables.

Removes a command by name regardless of source.

Removes every command contributed by a source.

Types

contribution_source()

@type contribution_source() :: :builtin | :config | {:extension, atom()}

Source that contributed registry entries.

register_error()

@type register_error() ::
  {:duplicate_name, atom(), existing_source :: contribution_source(),
   attempted_source :: contribution_source()}
  | {:duplicate_names, [atom()]}

Command registration failure reason.

server()

@type server() :: GenServer.server()

Registry server name or pid. Used as the ETS table name.

Functions

all(server)

@spec all(server()) :: [Minga.Command.t()]

Returns all registered commands as a list.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(server, name)

@spec lookup(server(), atom()) :: {:ok, Minga.Command.t()} | :error

Looks up a command by name.

register(server, name, description, execute)

@spec register(server(), atom(), String.t(), function()) ::
  :ok | {:error, register_error()}

Registers a config-owned command with the given name, description, and execute function.

register(server, source, name, description, execute)

@spec register(server(), contribution_source(), atom(), String.t(), function()) ::
  :ok | {:error, register_error()}

Registers a command with an explicit source.

register_command(server, cmd)

@spec register_command(server(), Minga.Command.t()) ::
  :ok | {:error, register_error()}

Registers a config-owned pre-built %Command{} struct.

register_command(server, source, cmd)

@spec register_command(server(), contribution_source(), Minga.Command.t()) ::
  :ok | {:error, register_error()}

Registers a pre-built %Command{} struct with an explicit source.

register_commands(server, source, commands)

@spec register_commands(server(), contribution_source(), [Minga.Command.t()]) ::
  :ok | {:error, register_error()}

Registers multiple commands for one source as a group.

register_provider(server, source, module)

@spec register_provider(server(), contribution_source(), module()) ::
  :ok | {:error, register_error()}

Registers every command returned by a provider module for one source.

reset()

@spec reset() :: :ok

Resets the registry to built-in commands only.

reset(server)

@spec reset(server()) :: :ok

start_link(opts \\ [])

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

Starts the command registry as a named GenServer that owns ETS tables.

unregister(server, name)

@spec unregister(server(), atom()) :: :ok

Removes a command by name regardless of source.

unregister_source(source)

@spec unregister_source(contribution_source()) :: :ok

Removes every command contributed by a source.

unregister_source(server, source)

@spec unregister_source(server(), contribution_source()) :: :ok