Macaw.Registry (macaw v0.1.2)

Copy Markdown View Source

A host's registry of components (spec/12 §1.1): built from the packages the host enables, and nothing else.

registry = Macaw.Registry.new!([Macaw.Builtin])
{:ok, Macaw.Builtin.Table} = Macaw.Registry.component(registry, "macaw.table")

Closed by default: new([]) holds nothing, and a component whose package isn't listed is unknown though its module is loaded. Names are matched by spelling; no atom is made from a document's name. Two components of one name across packages fail at boot, naming both.

Summary

Functions

A component by name, a string or an atom read as its spelling: {:ok, module} or :error.

Every component, {name, module}, in name order.

Every hook of the registry's packages (Macaw.Component.Package.hooks/1).

The registry of the listed packages: {:ok, registry}, or every fault at once, a package's own at [package] and a name two packages share as {:duplicate, name, [{module, package}, {module, package}]}.

The registry of the listed packages, or an ArgumentError with every fault: a host's boot.

The packages, as given, each once.

Types

t()

@type t() :: %Macaw.Registry{
  components: %{required(String.t()) => module()},
  packages: [module()]
}

Functions

component(registry, name)

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

A component by name, a string or an atom read as its spelling: {:ok, module} or :error.

components(registry)

@spec components(t()) :: [{String.t(), module()}]

Every component, {name, module}, in name order.

hooks(registry)

@spec hooks(t()) :: {:ok, map()} | {:error, [Macaw.Layers.Fault.t(), ...]}

Every hook of the registry's packages (Macaw.Component.Package.hooks/1).

new(packages)

@spec new([module()]) :: {:ok, t()} | {:error, [Macaw.Layers.Fault.t(), ...]}

The registry of the listed packages: {:ok, registry}, or every fault at once, a package's own at [package] and a name two packages share as {:duplicate, name, [{module, package}, {module, package}]}.

new!(packages)

@spec new!([module()]) :: t()

The registry of the listed packages, or an ArgumentError with every fault: a host's boot.

packages(registry)

@spec packages(t()) :: [module()]

The packages, as given, each once.