A named feature flag (a collection of gates) and its evaluation.
Summary
Functions
Evaluates the flag, returning whether it is enabled for the given input.
Builds a flag named name from a (possibly empty) list of gates.
Returns the variant chosen for the actor, or options[:default] (nil if not given).
Types
@type t() :: %Bandera.Flag{gates: [Bandera.Gate.t()], name: atom()}
Functions
Evaluates the flag, returning whether it is enabled for the given input.
With no :for, boolean, schedule, and percentage-of-time gates are consulted.
With for: item, actor gates are checked first, then group gates, then rule,
boolean, schedule, and percentage-of-actors gates. A flag with no gates is
disabled.
Examples
iex> Bandera.Flag.enabled?(Bandera.Flag.new(:f, [Bandera.Gate.new(:boolean, true)]))
true
iex> Bandera.Flag.enabled?(Bandera.Flag.new(:f))
false
iex> Bandera.Flag.enabled?(Bandera.Flag.new(:f, [Bandera.Gate.new(:actor, "u1", true)]), for: "u1")
true
@spec new(atom(), [Bandera.Gate.t()]) :: t()
Builds a flag named name from a (possibly empty) list of gates.
Examples
iex> Bandera.Flag.new(:my_flag)
%Bandera.Flag{name: :my_flag, gates: []}
iex> flag = Bandera.Flag.new(:my_flag, [Bandera.Gate.new(:boolean, true)])
iex> flag.gates
[%Bandera.Gate{type: :boolean, for: nil, enabled: true}]
Returns the variant chosen for the actor, or options[:default] (nil if not given).
Requires a variant gate to exist on the flag and :for to be a non-nil actor.
Passing for: nil or omitting :for also returns default. The bucket is
stable per actor+flag using the SHA-256 score from Bandera.Gate.score/2.
Examples
iex> flag = Bandera.Flag.new(:f, [Bandera.Gate.new(:variant, %{"a" => 1, "b" => 1})])
iex> v = Bandera.Flag.variant(flag, for: %{id: 1})
iex> v in ["a", "b"]
true