fun_with_flags v0.4.0 FunWithFlags

FunWithFlags, the Elixir feature flag library.

See the Usage notes for a more detailed explanation, and the Actor protocol documentation for more examples on how to work with Actor toggles.

Summary

Functions

Disables a feature flag

Enables a feature flag

Checks if a flag is enabled

Types

options()
options() :: Keyword.t

Functions

disable(flag_name, options \\ [])
disable(atom, options) :: {:ok, false}

Disables a feature flag.

Examples

iex> FunWithFlags.enable(:random_koala_gifs)
iex> FunWithFlags.enabled?(:random_koala_gifs)
true
iex> FunWithFlags.disable(:random_koala_gifs)
{:ok, false}
iex> FunWithFlags.enabled?(:random_koala_gifs)
false

Options

  • :for_actor - used to disable the flag for a specific term only. This can be anything.

Examples

iex> FunWithFlags.enable(:spider_sense)
{:ok, true}
iex> villain = %{name: "Venom"}
iex> FunWithFlags.disable(:spider_sense, for_actor: villain)
{:ok, false}
iex> FunWithFlags.enabled?(:spider_sense)
true
iex> FunWithFlags.enabled?(:spider_sense, for: villain)
false
enable(flag_name, options \\ [])
enable(atom, options) :: {:ok, true}

Enables a feature flag.

Examples

iex> FunWithFlags.enabled?(:super_shrink_ray)
false
iex> FunWithFlags.enable(:super_shrink_ray)
{:ok, true}
iex> FunWithFlags.enabled?(:super_shrink_ray)
true

Options

  • :for_actor - used to enable the flag for a specific term only. This can be anything.

Examples

iex> FunWithFlags.disable(:warp_drive)
{:ok, false}
iex> FunWithFlags.enable(:warp_drive, for_actor: "Scotty")
{:ok, true}
iex> FunWithFlags.enabled?(:warp_drive)
false
iex> FunWithFlags.enabled?(:warp_drive, for: "Scotty")
true
enabled?(flag_name, options \\ [])
enabled?(atom, options) :: boolean

Checks if a flag is enabled.

It can be invoked with just the flag name, as an atom, to check the general staus of a flag (i.e. the boolean gate).

Examples

iex> FunWithFlags.enabled?(:new_homepage)
false

Options

  • :for - used to specify a term for which the flag could have a specific rule.

Examples

iex> wizard = %{id: 42, name: "Harry Potter"}
iex> FunWithFlags.disable(:elder_wand)
iex> FunWithFlags.enable(:elder_wand, for_actor: wizard)
iex> FunWithFlags.enabled?(:elder_wand)
false
iex> FunWithFlags.enabled?(:elder_wand, for: wizard)
true
iex> other_wizard = %{id: 7, name: "Tom Riddle"}
iex> FunWithFlags.enabled?(:elder_wand, for: other_wizard)
false