View Source Teiserver.Config (Teiserver v0.0.1)

Config struct As with most things at this stage, heavily copied from Oban

Summary

Functions

Generate a Config struct after normalizing and verifying Teiserver options.

Verify configuration options.

Types

@type t() :: %Teiserver.Config{
  log: false | Logger.level(),
  name: Teiserver.name(),
  node: String.t(),
  prefix: false | String.t(),
  repo: module()
}

Functions

@spec new([Teiserver.option()]) :: t()

Generate a Config struct after normalizing and verifying Teiserver options.

See Teiserver.start_link/1 for a comprehensive description of available options.

Example

Generate a minimal config with only a :repo:

Teiserver.Config.new(repo: Teiserver.Test.Repo)
@spec validate([Teiserver.option()]) :: :ok | {:error, String.t()}

Verify configuration options.

This helper is used by new/1, and therefore by Teiserver.start_link/1, to verify configuration options when a Teiserver supervisor starts. It is provided publicly to aid in configuration testing, as test config may differ from prod config.

Example

Validating top level options:

iex> Teiserver.Config.validate(name: Teiserver)
:ok

iex> Teiserver.Config.validate(name: Teiserver, log: false)
:ok

iex> Teiserver.Config.validate(node: {:not, :binary})
{:error, "expected :node to be a binary, got: {:not, :binary}"}

Validating plugin options:

iex> Teiserver.Config.validate(plugins: [{Teiserver.Plugins.Pruner, max_age: 60}])
:ok

iex> Teiserver.Config.validate(plugins: [{Teiserver.Plugins.Pruner, max_age: 0}])
{:error, "invalid value for :plugins, expected :max_age to be a positive integer, got: 0"}