QolUp.ConfigFile (qol_up v1.0.3)

GenServer that reads from a config file.

Link to this section Summary

Types

The name of a configuration item, the list variation is for nesting of items.

List of options

Available options for the GenServer

Functions

Returns a specification to start this module under a supervisor.

Get a config item by name or path through config file

Get an item, raising if not found. See get_item/1

Parse the config file. This is automatically called when the genserver starts. Call it again if the config file changes and need to be reloaded. If watch_file_system: true is passed to start_link/1, then the GenServer will automatically watch the config file and will automatically reload it when it changes.

Put a config item by name or path. This does not update an underlying config file; it is only an in-memory ephemeral change.

Start the genserver

Link to this section Types

Specs

item_name() :: String.t() | [String.t()]

The name of a configuration item, the list variation is for nesting of items.

Specs

opts_list() :: [opts_t()]

List of options

Specs

opts_t() ::
  {:config_file, String.t()} | {:watch_fs, boolean()} | {:name, atom()}

Available options for the GenServer

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

get_item(name \\ __MODULE__, item)

Specs

get_item(atom(), item_name()) :: {:ok, any()} | {:error, any()}

Get a config item by name or path through config file

Parameters

  • name The name of the GenServer
  • item [String.t] or String.t An item or path to an item to retrieve As in "foo", or ["foo"], or ["foo", "bar"]

    Returns

  • {:ok, value} All is well
  • {:error, :not_found} Item was not found in the config
Link to this function

get_item!(name \\ __MODULE__, item)

Specs

get_item!(atom(), item_name()) :: any()

Get an item, raising if not found. See get_item/1

Parameters

  • name The name of the GenServer
    • item [String.t] or String.t An item or path to an item to retrieve As in "foo", or ["foo"], or ["foo", "bar"]

Returns

  • value
Link to this function

parse_config_file(name \\ __MODULE__)

Specs

parse_config_file(atom()) :: :ok | {:error, any()}

Parse the config file. This is automatically called when the genserver starts. Call it again if the config file changes and need to be reloaded. If watch_file_system: true is passed to start_link/1, then the GenServer will automatically watch the config file and will automatically reload it when it changes.

Parameters

  • name The name of the GenServer

    Returns

  • :ok All is well
  • {:error, reason} Failed for reason
Link to this function

put_item(name \\ __MODULE__, item, value)

Specs

put_item(atom(), item_name(), any()) :: :ok

Put a config item by name or path. This does not update an underlying config file; it is only an in-memory ephemeral change.

Parameters

  • name The name of the GenServer
    • item [String.t] or String.t An item or path to an item to retrieve As in "foo", or ["foo"], or ["foo", "bar"]
  • value String.t value to assign to item

Returns

  • :ok All is well
Link to this function

start_link(opts)

Specs

start_link(opts_list()) :: GenServer.on_start()

Start the genserver

Parameters

  • opts, an opts_list():
    • name Name to give the GenServer; if not specified, then QolUp.ConfigFile is used.
    • config_file Path to the config file to load, required
    • watch_fs Whether (true) or not to watch the config file and automatically reload it when it changes, defaults to false

Returns