FeatureFlippers
A helpful and simple way to use feature toggles/flippers/flags on your Elixir code, built around Application configurations. It is intended to allow developers to push code to production in a disabled state and carefully control whether or not the code is enabled or disabled without doing additional releases.
How to use
Declare a module where you’ll define the available FFs and just declare them all:
defmodule Flags do
use FeatureFlippers, otp_app: :my_app
feature_flipper :foo?
feature_flipper :bar?, expires: ~D[2000-01-01]
feature_flipper :baz?, disabled: true
feature_flipper :foobar?, default: true
end
In your code, you can use the example module Flags as in:
if Flags.foo? do
... new code ...
else
... original code ...
end
In order to turn them on/off, just declare them in your config/config.exs:
config :my_app, Flags,
foo?: true
bar?: false
baz: true
You can also set them in runtime by updating the corresponding config key Flags:
Application.get_env(:my_app, Flags)
|> Keyword.update(:bar?, true, fn _ -> true end)
|> (&Application.put_env(:my_app, Flags, &1)).()While running unit tests, you might want to enable them all:
Flags.all()
|> Enum.map(fn key -> {key, true} end)
|> (&Application.put_env(:my_app, Flags, &1)).()You can discover which feature flippers have expired calling:
iex> Flags.expired()
[:bar]Installation
The package can be installed by adding feature_flippers to your list of dependencies in mix.exs:
def deps do
[
{:feature_flippers, "~> 0.1.0"}
]
endDocumentation can be found at https://hexdocs.pm/feature_flippers.