clj-env.core
A library for defining environments by setting ^:dynamic identities using
file defined envs. There are a few ways to use this:
First, via the `with-env` macro, like so:
(with-env (do-something))
Second, by loading an env to apply globally:
(do
(load-env! env)
(do-something))
The former is useful for narrow scopes, the latter to ensure that all threads
use the same bindings until changed.
backup-vars
(backup-vars vars)
Implementation detail.
Backs up multiple vars current values, returns a map of var=>value.
bindings-map
(bindings-map env)
Converts the env file format into a map that can be passed to with-bindings.
Throws an Exception if there is an invalid config.
invalid-override-exception
(invalid-override-exception ns name)
(invalid-override-exception var)
Implementation detail.
Creates an IllegalArgumentException with details of the bad override
load!
(load! src)
Attempts to load a config. `src` can be anything `slurp` can handle, such as
a string representing a file or resource path, a java.net URI/URL, or
java.io.File.
Loads `env`, backing up any vars to be rebound and then binding vars globally
to their new values.
Returns a delay that, when forced, restores all vars to their original values.
overrides
Implementation detail. Holds the env bindings as a map of
namespace qualified vars to values. This tracks the calls to
`set-var!` which can be useful to inspect what has been
modified.
resolve-bindings
(resolve-bindings {:keys [ns bindings]})
Resolves the fully-qualified bindings. Transforms this:
{:ns some.namespace
:bindings {:some-var 1
:a-value :foo}}
Into a `with-bindings` compatible bindings map, like so:
{#'some.namespace/some-var 1
#'some.namespace/a-value :foo}
set-var!
(set-var! var value)
(set-var! [var value])
Implementation detail.
Sets a single dynamic var to the specified value, regardless of its
present value.
Note: this implementation could result in inconsistencies if it is called
concurrently to modify the same var.
set-vars!
(set-vars! var-map)
Implementation detail.
Sets multiple dynamic vars specified in the input map. The input map must be
a map of var => value.
to-string-keys
(to-string-keys map)
validate
(validate env)
Returns true if the specified env is valid, otherwise a list of errors
with-env
macro
(with-env env & body)
Evaluates body with env bindings.