View Source Unleash.Strategy behaviour (Unleash v1.9.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

Link to this section 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.

Link to this section 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

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

Examples

@behaviour Unleash.Strategy

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

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