Raxol.Core.Config.Manager (Raxol v0.5.0)

View Source

Configuration manager for the Raxol Terminal Emulator. Provides a unified interface for managing all configuration options, including loading, validation, and runtime updates.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes a configuration value.

Gets a configuration value.

Gets all configuration values.

Reloads configuration from the file.

Sets a configuration value.

Starts the configuration manager.

Updates a configuration value using a function.

Types

config_key()

@type config_key() :: atom()

config_opts()

@type config_opts() :: keyword()

config_value()

@type config_value() :: term()

validation_result()

@type validation_result() :: :ok | {:error, String.t()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete(key, opts \\ [])

Deletes a configuration value.

Parameters

  • key - The configuration key
  • opts - Additional options
    • :persist - Whether to persist the deletion (default: true)

Returns

  • :ok - If the value was deleted successfully
  • {:error, reason} - If the value could not be deleted

get(key, default \\ nil)

Gets a configuration value.

Parameters

  • key - The configuration key
  • default - Default value if key is not found (optional)

Returns

  • The configuration value or default

get_all()

Gets all configuration values.

Returns

  • Map of all configuration values

reload()

Reloads configuration from the file.

Returns

  • :ok - If the configuration was reloaded successfully
  • {:error, reason} - If the configuration could not be reloaded

set(key, value, opts \\ [])

Sets a configuration value.

Parameters

  • key - The configuration key
  • value - The configuration value
  • opts - Additional options
    • :validate - Whether to validate the value (default: true)
    • :persist - Whether to persist the value (default: true)

Returns

  • :ok - If the value was set successfully
  • {:error, reason} - If the value could not be set

start_link(opts \\ [])

Starts the configuration manager.

Options

  • :config_file - Path to the configuration file (default: "config/raxol.exs")
  • :env - Environment to load (default: Mix.env())
  • :validate - Whether to validate configuration (default: true)

Returns

  • {:ok, pid} - If the manager starts successfully
  • {:error, reason} - If the manager fails to start

update(key, fun, opts \\ [])

Updates a configuration value using a function.

Parameters

  • key - The configuration key
  • fun - Function to update the value
  • opts - Additional options
    • :validate - Whether to validate the value (default: true)
    • :persist - Whether to persist the value (default: true)

Returns

  • :ok - If the value was updated successfully
  • {:error, reason} - If the value could not be updated