Unleash v1.7.0 Unleash.Strategy behaviour View Source

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 Functions

Link to this function

log_result(result, name)

View Source
log_result({boolean(), map()}, String.t()) :: boolean()
log_result(boolean(), String.t()) :: boolean()

Link to this section Callbacks

Link to this callback

enabled?(parameters, context)

View Source
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