Unleash. Strategy behaviour
(Unleash v5.1.2)
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
Summary
Types
Debug metadata returned alongside a strategy result to explain how it was evaluated.
Callbacks
You can implement 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.
Types
Callbacks
@callback enabled?(parameters :: map(), context :: Unleash.context()) :: boolean() | {boolean(), map()}
You can implement 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 parameters returned from the Unleash server. This can be whatever you like, such as a configured list ofuserIds.context- The context passed intoUnleash.enabled?/2.
Examples
@behaviour Unleash.Strategy
def enabled?(params, context), do: {false, params}
def enabled(params, %{}), do: false