Current section
Files
Jump to
Current section
Files
lib/plato/registry.ex
defmodule Plato.Registry do
@moduledoc """
A registry for storing and retrieving content schemas.
This uses an Agent to keep schemas in memory.
"""
use Agent
def start_link(_opts) do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end
@doc """
Registers a schema in the registry.
"""
def register_schema(%Plato.Schema{} = schema) do
Agent.update(__MODULE__, fn schemas ->
Map.put(schemas, schema.name, schema)
end)
end
@doc """
Gets a schema by name.
"""
def get_schema(name) do
Agent.get(__MODULE__, fn schemas ->
Map.get(schemas, name)
end)
end
@doc """
Lists all registered schemas.
"""
def list_schemas do
Agent.get(__MODULE__, fn schemas ->
Map.values(schemas)
end)
end
@doc """
Clears all schemas (useful for testing).
"""
def clear do
Agent.update(__MODULE__, fn _ -> %{} end)
end
end