Botica.Flags.Flag (Botica v2.2.0)

Copy Markdown View Source

Struct representing a single feature flag.

Fields

  • :name — Atom identifier (e.g. :new_dashboard)
  • :enabled — Whether the flag is on. For rollout flags this is the master switch; individual users are gated by the rollout percentage.
  • :default — Fallback value when the flag is queried but not defined. Most flags use default: false; if you want safe-by-default for risky features, use default: false.
  • :description — Optional human-readable explanation
  • :rollout — Gradual rollout definition. Either a legacy integer 0..100 percentage, or a map:
    • %{type: :percentage, value: 25} — first 25% of entities
    • %{type: :user_list, users: ["lorenzo"]} — explicit user list
    • %{type: :attribute, key: "tenant", values: ["acme"]} — match a context attribute against allowed values nil means binary on/off (no gradual rollout).
  • :created_at — When the flag was first defined
  • :updated_at — Last modification timestamp

Summary

Functions

Creates a new Flag with the given attributes. Fills timestamps automatically.

Types

rollout_t()

@type rollout_t() ::
  non_neg_integer()
  | %{type: :percentage, value: non_neg_integer()}
  | %{type: :user_list, users: [String.t()]}
  | %{type: :attribute, key: String.t(), values: [String.t()]}

t()

@type t() :: %Botica.Flags.Flag{
  created_at: DateTime.t(),
  default: boolean(),
  description: String.t() | nil,
  enabled: boolean(),
  name: atom(),
  rollout: rollout_t() | nil,
  updated_at: DateTime.t()
}

Functions

new(name, opts \\ [])

@spec new(
  atom(),
  keyword()
) :: t()

Creates a new Flag with the given attributes. Fills timestamps automatically.

Examples

iex> Botica.Flags.Flag.new(:beta, default: false)
%Botica.Flags.Flag{name: :beta, enabled: false, default: false, ...}

iex> Botica.Flags.Flag.new(:rate_limiting, default: false, rollout: 25)
%Botica.Flags.Flag{name: :rate_limiting, rollout: 25, ...}