Services.Globals (fnord v0.8.83)

View Source

Drop-in-ish replacement for Application env that shadows values down a process tree. Think: dynamic scope via process ancestry.

  • put_env/3 sets an override in the current tree (installing the caller as a root if needed).
  • get_env/3 first checks the current tree's overrides, then falls back to Application.get_env/3.
  • delete_env/2 removes the tree-local override.
  • get_all_env/1 lists all overrides in the current tree, overlaying them on top of Application.get_all_env/1 if the caller is the root.
  • put_all_env/2 bulk-inserts multiple overrides for one or more apps in the current tree (installing the caller as a root if needed).
  • install_root/0 explicitly installs the caller as a shadowing root (rarely needed; put_env/3 auto-installs).
  • current_root/0 returns the current shadowing root PID (or nil). Useful for debugging.
  • explain/0 prints the current process tree and its overrides (for debugging).

Summary

Functions

Returns a specification to start this module under a supervisor.

Return the current shadowing root PID (or nil). Useful for debugging.

Delete a tree-local override (no-op if none). Returns :ok.

Get all tree-local overrides for the given app, overlaying them on top of Application.get_all_env/1 if the caller is the root.

Get a value with tree-local shadowing, else falls back to Application.get_env/3.

Install the caller as a shadowing root explicitly (rarely needed; put_env/3 auto-installs).

Bulk put multiple overrides for one or more apps in the current tree (installing the caller as a root if needed).

Put a tree-local override. Creates a root for the current process if none exists.

Types

app()

@type app() :: atom()

key()

@type key() :: term()

value()

@type value() :: term()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

current_root()

@spec current_root() :: pid() | nil

Return the current shadowing root PID (or nil). Useful for debugging.

delete_env(app, key)

@spec delete_env(atom(), term()) :: :ok

Delete a tree-local override (no-op if none). Returns :ok.

explain()

get_all_env(app)

@spec get_all_env(atom()) :: keyword()

Get all tree-local overrides for the given app, overlaying them on top of Application.get_all_env/1 if the caller is the root.

get_env(app, key, default \\ nil)

@spec get_env(atom(), term(), term()) :: term()

Get a value with tree-local shadowing, else falls back to Application.get_env/3.

install_root()

@spec install_root() :: :ok

Install the caller as a shadowing root explicitly (rarely needed; put_env/3 auto-installs).

put_all_env(app_kvs_list, kvs \\ [])

@spec put_all_env(
  [{app(), [{key(), value()}]}],
  keyword()
) :: :ok

Bulk put multiple overrides for one or more apps in the current tree (installing the caller as a root if needed).

put_env(app, key, value)

@spec put_env(atom(), term(), term()) :: :ok

Put a tree-local override. Creates a root for the current process if none exists.

start_link(opts \\ [])