View Source Unleash.Context (Unleash v3.0.0)

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

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.

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()
}

Functions

Link to this function

atomize_context_key(string_key)

View Source
@spec atomize_context_key(String.t()) :: atom()
@spec find(t(), atom() | String.t()) :: term()

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:

  1. 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.
  2. 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.

Link to this function

stringify_context_key(atom_key)

View Source
@spec stringify_context_key(atom()) :: String.t()