An app-config accessor with a per-process override layer for test isolation.
use it once to bind it to your OTP application:
defmodule MyApp.Config do
use Ambient.Config, otp_app: :my_app
endThis generates the domain API – get/2, put/2, revert/1, reset/0 –
where get/2 reads a per-process override first (via
Ambient.ProcessOverride), then falls back to
Application.get_env(:my_app, key, default).
Underneath, Ambient.Value supplies the generic layer those wrap
(put_override/2, delete_override/1, delete_all/0) plus overridden?/1,
allow/2, set_shared/1 and set_private/0. You can use Ambient.Value
directly to build overridable values of your own.
Why not Application.put_env/3 in tests?
Application.put_env/3 is global – concurrent async: true tests clobber
each other. put/2 is process-local, inherited by spawned children
($callers + allow/2), and auto-cleaned on exit. Safe under async: true.
Usage
# production / app code
MyApp.Config.get(:feature_x_enabled, false)
# tests
MyApp.Config.put(:feature_x_enabled, true)
MyApp.Config.revert(:feature_x_enabled)
MyApp.Config.reset()
# for a GenServer that reads config in its own process:
MyApp.Config.allow(genserver_pid)Remember to start the override server for the generated table in
test/test_helper.exs:
Ambient.start_servers([MyApp.Config])