Gno.Service.Setup.Extension behaviour (Gno v0.1.0)

Copy Markdown View Source

Behavior for Gno.Service.Setup extensions with custom setup logic.

Summary

Callbacks

Checks if the service's repository is set up, i.e. exists.

Performs extension-specific initialization during setup.

Performs extension-specific teardown.

Validates the setup state after all initialization is complete.

Functions

Provides default implementations of the setup extension callbacks.

Callbacks

check_setup(t, keyword)

@callback check_setup(
  Gno.Service.t(),
  keyword()
) :: :ok | {:error, term()}

Checks if the service's repository is set up, i.e. exists.

Called during setup to verify if the repository already exists and is accessible. Implementations should implement a minimal check to verify the repository exists. More detailed validation should be done in the validate/2 callback.

setup t, keyword

@callback setup(
  Gno.Service.t(),
  keyword()
) :: {:ok, Gno.Service.t()} | {:error, term()}

Performs extension-specific initialization during setup.

Called after the repository has been initialized but before validation. The extension can perform any additional setup steps needed, such as:

  • Creating application-specific graphs
  • Setting up initial data structures
  • Configuring external systems

Returns the service (potentially modified) on success.

teardown(t, keyword)

@callback teardown(
  Gno.Service.t(),
  keyword()
) :: :ok | {:error, term()}

Performs extension-specific teardown.

validate(t, keyword)

@callback validate(
  Gno.Service.t(),
  keyword()
) :: :ok | {:error, term()}

Validates the setup state after all initialization is complete.

Called as the final step of setup to ensure everything is properly configured. Should check that all required components are in place and properly initialized.

Functions

__using__(opts)

(macro)

Provides default implementations of the setup extension callbacks.

Examples

defmodule MyApp.Setup do
  use Gno.Service.Setup.Extension

  @impl true
  def setup(service, opts) do
    # Custom setup logic here
    {:ok, service}
  end
end