Unleash. Context
(Unleash v5.1.2)
View Source
The Unleash Context, mostly used to evaluate conditional activation strategies. https://docs.getunleash.io/reference/unleash-context.
The Context has a predefined set of fields,
but custom context properties can be set in the :properties field.
Note that, for hystorical / backwards-compatibility reasons,
both atom and string keys are allowed in the properties map.
You are encouraged to use find/2 to lookup context values in a way
that handles fallback to properties and the different style of keys correctly.
Summary
Functions
Converts a camelCase string context key to its snake_case atom form (may create atoms).
Looks for a context value, taking care of some of the nasty details
like fallback to :properties (a.k.a. custom context values)
with support for both atom and string keys.
Converts a snake_case atom context key to its camelCase string form.
Types
@type t() :: %{ optional(:app_name) => String.t(), optional(:environment) => String.t(), optional(:user_id) => String.t(), optional(:session_id) => String.t(), optional(:remote_address) => String.t(), optional(:properties) => %{required(atom() | String.t()) => String.t()}, optional(:current_time) => String.t() }
@type value() :: term()
A looked-up context value: a standard field, a custom property, or nil.
Functions
Converts a camelCase string context key to its snake_case atom form (may create atoms).
Looks for a context value, taking care of some of the nasty details
like fallback to :properties (a.k.a. custom context values)
with support for both atom and string keys.
Specifically:
- If the key is a standard context key (either in its atom or string form), it looks for it in the standard context fields, without fallbacking to properties.
- Otherwise, it looks for it in properties, trying both the atomized and the stringified version of the key, starting from the supplied one.
NOTE that this can create atom at runtimes, which is dangerous. It is highly recommended you do not call this function with values from untrusted / unbounded sources.
Converts a snake_case atom context key to its camelCase string form.