# `PgFlow.FlowRegistry`
[🔗](https://github.com/agoodway/pgflow/blob/v0.1.0/lib/pgflow/flow_registry.ex#L1)

Registry for flow definitions using an ETS table.

The registry stores flow modules and their metadata, allowing flows to be
looked up by module name or slug. This is a GenServer that manages an ETS
table for fast concurrent reads.

## Usage

    # Register a flow
    :ok = PgFlow.FlowRegistry.register(MyApp.Flows.ProcessOrder)

    # Get a flow definition
    {:ok, flow_def} = PgFlow.FlowRegistry.get(MyApp.Flows.ProcessOrder)
    {:ok, flow_def} = PgFlow.FlowRegistry.get(:process_order)

    # List all flows
    flows = PgFlow.FlowRegistry.list()

    # Unregister a flow
    :ok = PgFlow.FlowRegistry.unregister(MyApp.Flows.ProcessOrder)

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get`

```elixir
@spec get(module() | atom()) :: {:ok, map()} | {:error, :not_found}
```

Gets a flow definition by module or slug.

## Examples

    {:ok, flow_def} = PgFlow.FlowRegistry.get(MyApp.Flows.ProcessOrder)
    {:ok, flow_def} = PgFlow.FlowRegistry.get(:process_order)
    {:error, :not_found} = PgFlow.FlowRegistry.get(:unknown_flow)

# `list`

```elixir
@spec list() :: [map()]
```

Lists all registered flows.

Returns a list of flow definitions.

## Examples

    flows = PgFlow.FlowRegistry.list()
    #=> [%{module: MyApp.Flows.ProcessOrder, slug: :process_order, ...}, ...]

# `register`

```elixir
@spec register(module()) ::
  :ok | {:error, {:not_loaded, module()} | {:invalid_flow_module, module()}}
```

Registers a flow module in the registry.

The flow module must implement the PgFlow.Flow behaviour (via `use PgFlow.Flow`)
and expose flow metadata via the `__pgflow_definition__/0` callback.

Returns `:ok` on success, `{:error, reason}` otherwise. Reasons:

  * `{:not_loaded, module}` — the module could not be loaded
  * `{:invalid_flow_module, module}` — the module is loaded but does not
    implement the `PgFlow.Flow` behaviour

## Examples

    :ok = PgFlow.FlowRegistry.register(MyApp.Flows.ProcessOrder)
    {:error, {:invalid_flow_module, Enum}} = PgFlow.FlowRegistry.register(Enum)

# `register!`

```elixir
@spec register!(module()) :: :ok
```

Like `register/1`, but raises `ArgumentError` on invalid modules.

# `start_link`

Starts the FlowRegistry GenServer.

# `unregister`

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

Unregisters a flow module from the registry.

## Examples

    :ok = PgFlow.FlowRegistry.unregister(MyApp.Flows.ProcessOrder)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
