View Source Unleash.Strategy behaviour (Unleash v1.10.0)

Used to extend the client and create custom strategies. To do so, use this module within your custom strategy and implmenent enabled?/2. Provide a name that is human-readable, as it is logged.

defmodule MyApp.CustomStrategy
  use Unleash.Strategy, name: "CustomStrategy"

  def enabled?(_params, _context), do: true
end

Summary

Callbacks

You can implmenet this callback a couple of ways, returning a bare boolean() or a {boolean, map()}. The latter is preferred, as it generates a :debug level log entry detailing the name of the strategy, the result, and the contents of map(), in an effort to help understand why the result was what it was.

Callbacks

Link to this callback

enabled?(parameters, context)

View Source
@callback enabled?(parameters :: map(), context :: Unleash.context()) ::
  boolean() | {boolean(), map()}

You can implmenet this callback a couple of ways, returning a bare boolean() or a {boolean, map()}. The latter is preferred, as it generates a :debug level log entry detailing the name of the strategy, the result, and the contents of map(), in an effort to help understand why the result was what it was.

Arguments

  • parameters - A map of paramters returned from the Unleash server. This can be whatever you like, such as a configured list of userIds.
  • context - The context passed into Unleash.enabled?/3.

Examples

@behaviour Unleash.Strategy

def enabled?(params, context), do: {false, params}

def enabled(params, %{}), do: false