View Source Bond.Config (Bond v1.1.0)
Runtime control over which kinds of contract Bond evaluates.
Bond has two configuration layers:
Compile-time —
config :bond, <kind>: true | false | :purge(read viaApplication.compile_env/3), plus per-module:overridesanduse Bondoptions. These are baked into each generated call site.:purgeremoves a kind's code entirely (zero runtime cost, not toggleable). SeeBondfor the full set of keys.Runtime — this module.
enable/1,disable/1, andput/2flip a kind on or off globally without recompiling. The state lives in a single:persistent_termentry read on every contracted call, so the gate stays cheap.
Kinds
:preconditions, :postconditions, :invariants, and :checks (for Bond.check/1,2).
How runtime and compile-time interact
On first use the runtime state is seeded from application env, so config :bond, … in
both config.exs and config/runtime.exs is honoured. A kind with no global setting is
:unset and falls back to the call site's compile-time default (including per-module
:overrides). A value set here overrides that fallback until reset/0.
Runtime
Application.put_envis not liveSetting
Application.put_env(:bond, :preconditions, false)after the first contracted call has run has no effect — the runtime state is cached. Usedisable/1/enable/1, or callreset/0to re-seed from current application env.
The chain
Bond enforces preconditions ≤ postconditions ≤ invariants: disabling a lower kind also
skips the higher ones (with a one-time log). These setters are pure writes — they do not
cascade; the chain is applied when contracts are evaluated. To turn everything off, disable
:preconditions (or each kind explicitly).
Examples
# Disable precondition checks globally at runtime
Bond.Config.disable(:preconditions)
# Re-enable
Bond.Config.enable(:preconditions)
# Inspect the effective global state
Bond.Config.all()
#=> %{preconditions: false, postconditions: true, invariants: true, checks: true}
# Drop all runtime overrides, re-seeding from application env
Bond.Config.reset()Performance note
Each
put/2/enable/1/disable/1/reset/0writes:persistent_term, which triggers a global GC scan. This is fine for setup and occasional toggles; do not toggle per call.
Summary
Functions
Returns the effective global runtime state for every kind as a map of booleans.
Disables runtime evaluation of kind. Equivalent to put(kind, false).
Enables runtime evaluation of kind. Equivalent to put(kind, true).
Returns whether kind is enabled in the global runtime state.
The list of contract kinds this module controls.
Sets the global runtime mode for kind to enabled?.
Drops all runtime overrides set through this module, re-seeding from current application env on the next contracted call. Useful in tests to restore a clean baseline.
Types
@type kind() :: :preconditions | :postconditions | :invariants | :checks
A contract kind that can be toggled at runtime.
Functions
Returns the effective global runtime state for every kind as a map of booleans.
Like enabled?/1, this is the global view and does not reflect per-module :overrides.
@spec disable(kind()) :: :ok
Disables runtime evaluation of kind. Equivalent to put(kind, false).
@spec enable(kind()) :: :ok
Enables runtime evaluation of kind. Equivalent to put(kind, true).
Returns whether kind is enabled in the global runtime state.
Reflects the global setting only; modules compiled with per-module :overrides may differ
at their own call sites. When kind has no global setting, falls back to the application
env default (and true if none is configured).
@spec kinds() :: [kind()]
The list of contract kinds this module controls.
Sets the global runtime mode for kind to enabled?.
Overrides both the application-env seed and the call site's compile-time default until
reset/0.
@spec reset() :: :ok
Drops all runtime overrides set through this module, re-seeding from current application env on the next contracted call. Useful in tests to restore a clean baseline.