View Source Unleash (Unleash v1.9.0)

If you have no plans on extending the client, then Unleash will be the main usage point of the library. Upon starting your app, the client is registered with the unleash server, and two GenServers are started, one to fetch and poll for feature flags from the server, and one to send metrics.

Configuring :disable_client to true disables both servers as well as registration, while configuring :disable_metrics to true disables only the metrics GenServer.

Link to this section Summary

Types

The context needed for a few activation strategies. Check their documentation for the required key.

Functions

Checks if the given feature is enabled. Checks as though an empty context was passed in.

Checks if the given feature is enabled.

Link to this section Types

@type context() :: %{
  user_id: String.t(),
  session_id: String.t(),
  remote_address: String.t()
}

The context needed for a few activation strategies. Check their documentation for the required key.

  • :user_id is the ID of the user interacting with your system, can be any String.t()
  • session_id is the ID of the current session in your system, can be any String.t()
  • remote_address is the address of the user interacting with your system, can be any String.t()

Link to this section Functions

Link to this function

enabled?(feature, default)

View Source
@spec enabled?(atom() | String.t(), boolean()) :: boolean()

Checks if the given feature is enabled. Checks as though an empty context was passed in.

examples

Examples

iex> Unleash.enabled?(:my_feature, false)
false

iex> Unleash.enabled?(:my_feature, true)
true
Link to this function

enabled?(feature, context \\ %{}, default \\ false)

View Source
@spec enabled?(atom() | String.t(), map(), boolean()) :: boolean()

Checks if the given feature is enabled.

If :disable_client is true, simply returns the given default.

If :disable_metrics is true, nothing is logged about the given toggle.

examples

Examples

iex> Unleash.enabled?(:my_feature)
false

iex> Unleash.enabled?(:my_feature, context)
false

iex> Unleash.enabled?(:my_feature, context, true)
false
Link to this function

get_variant(name, context \\ %{}, fallback \\ Variant.disabled())

View Source
@spec get_variant(atom() | String.t(), map(), Unleash.Variant.result()) ::
  Unleash.Variant.result()

Returns a variant for the given name.

If :disable_client is true, returns the fallback.

A variant allows for more complicated toggling than a simple true/false, instead returning one of the configured variants depending on whether or not there are any overrides for a given context value as well as factoring in the weights for the various weight options.

examples

Examples

iex> Unleash.get_variant(:test)
%{enabled: true, name: "test", payload: %{...}}

iex> Unleash.get_variant(:test)
%{enabled: false, name: "disabled"}
Link to this function

is_enabled?(feature, default)

View Source
@spec is_enabled?(atom() | String.t(), boolean()) :: boolean()

Aliased to enabled?/2

Link to this function

is_enabled?(feature, context \\ %{}, default \\ false)

View Source
@spec is_enabled?(atom() | String.t(), map(), boolean()) :: boolean()

Aliased to enabled?/3