### Execute Bundle and Install Source: https://github.com/flippercloud/flipper/blob/main/README.md Commands to install the dependencies or the gem directly. ```bash $ bundle ``` ```bash $ gem install flipper ``` -------------------------------- ### Start the Flipper Client Source: https://github.com/flippercloud/flipper/blob/main/examples/cloud/poll_interval/README.md Run the client to poll the server and observe interval changes. ```bash bundle exec ruby examples/cloud/poll_interval/client.rb ``` -------------------------------- ### Start the Flipper Test Server Source: https://github.com/flippercloud/flipper/blob/main/examples/cloud/poll_interval/README.md Run the test server to control headers sent to the client. ```bash bundle exec ruby examples/cloud/poll_interval/server.rb ``` -------------------------------- ### Start Local UI Server Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Start the Flipper UI development server on port 9999. This allows for testing the web interface locally. ```ruby script/server ``` -------------------------------- ### Flipper Test Setup Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Set up Flipper with a Memory adapter before tests and clean up afterwards. ```ruby describe "Feature flags" do before do @flipper = Flipper.new(Flipper::Adapters::Memory.new) Flipper.instance = @flipper end after do Flipper.instance = nil end end ``` -------------------------------- ### Install Gems with Docker Compose Source: https://github.com/flippercloud/flipper/blob/main/docs/DockerCompose.md Installs project gems within the application container. This command runs bundle install. ```bash docker-compose run --rm app bundle install ``` -------------------------------- ### Install Flipper Gem Source: https://github.com/flippercloud/flipper/blob/main/README.md Add the Flipper gem and a storage adapter to your Gemfile. ```ruby gem 'flipper' ``` ```ruby gem 'flipper-active_record' ``` -------------------------------- ### Flipper Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/README.md Configure the Flipper adapter and middleware during application setup. ```ruby Flipper.configure do |config| config.adapter { Flipper::Adapters::Redis.new(redis) } config.use Flipper::Adapters::Memoizable end ``` -------------------------------- ### Start Interactive Console Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Launch an interactive Pry console with Flipper loaded. Useful for experimenting with the library and debugging. ```ruby script/console ``` -------------------------------- ### Bootstrap Development Dependencies Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Install all project dependencies using Bundler and set up binstubs. This is a prerequisite for running most development commands. ```ruby script/bootstrap ``` -------------------------------- ### Feature Gate Evaluation Order Example Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/06-gates.md Demonstrates how Flipper evaluates gates in a specific order (Boolean, Expression, Actor, Group, Percentage). A feature is enabled if any gate is open. This example shows how a boolean gate being enabled immediately returns true, otherwise it checks subsequent gates. ```ruby # Feature has multiple gates enabled: flipper.enable(:feature) # Boolean gate = true flipper.enable_actor(:feature, admin) flipper.enable_group(:feature, :beta_users) # Check with any user: flipper.enabled?(:feature, any_user) # => true (boolean gate is true) # If boolean is disabled, check other gates: flipper.disable(:feature) flipper.enabled?(:feature, admin) # => true (actor gate matches) flipper.enabled?(:feature, regular_user) # => false (no other gates match) ``` -------------------------------- ### Memoizer Middleware Installation (Rails) Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Install the Memoizer middleware in a Rails application by adding it to the application's middleware stack. ```ruby # config/application.rb (Rails) config.middleware.use Flipper::Middleware::Memoizer ``` -------------------------------- ### Preloading Features on App Start Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Load all Flipper features into memory when the application initializes. This is done using `Flipper.preload_all` within the `after_initialize` callback. ```ruby # Preload all features on app start Rails.application.config.after_initialize do Flipper.preload_all end ``` -------------------------------- ### REST API Setup Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Mount the Flipper API application in your Rails routes to expose the REST API endpoints. ```APIDOC ## REST API Setup ### Description Mount the Flipper API application in your Rails routes to expose the REST API endpoints. ### Method ```ruby # config/routes.rb mount Flipper::Api.app => '/api/features' ``` ``` -------------------------------- ### Configure Flipper Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Configure the Flipper adapter within the Flipper.configure block. This setup is necessary before creating the UI app. ```ruby Flipper.configure do |config| config.adapter do # Your adapter setup end end app = Flipper::UI.app ``` -------------------------------- ### Complete Feature Lifecycle with cURL Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md This example shows the full lifecycle of a feature using cURL commands: creation, enabling for a percentage of users, enabling for a specific actor, checking its state, enabling for everyone, and deletion. ```bash # Create a feature curl -X POST http://localhost:3000/flipper/api/features \ -H 'Content-Type: application/json' \ -d '{"name": "search"}' ``` ```bash # Enable for 10% of users curl -X POST http://localhost:3000/flipper/api/features/search/percentage_of_actors \ -H 'Content-Type: application/json' \ -d '{"percentage": 10}' ``` ```bash # Enable for specific admin curl -X POST http://localhost:3000/flipper/api/features/search/actors \ -H 'Content-Type: application/json' \ -d '{"flipper_id": "admin_1"}' ``` ```bash # Check current state curl http://localhost:3000/flipper/api/features/search ``` ```bash # Enable for everyone curl -X POST http://localhost:3000/flipper/api/features/search/boolean \ -H 'Content-Type: application/json' ``` ```bash # Delete the feature curl -X DELETE http://localhost:3000/flipper/api/features/search ``` -------------------------------- ### Create Flipper UI Rack Application with Custom Middleware Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Create the Flipper UI Rack application, optionally accepting a Flipper instance and custom options. This example demonstrates adding basic HTTP authentication middleware. ```ruby app = Flipper::UI.app do |builder| builder.use Rack::BasicAuth do |username, password| username == "admin" && password == "secret" end end ``` -------------------------------- ### Adapter-Specific Error Handling Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Example of catching adapter-specific errors (e.g., Redis, ActiveRecord) in addition to Flipper errors. ```ruby begin flipper.enabled?(:search) rescue Redis::ConnectionError => e # Handle Redis connection failure rescue ActiveRecord::ConnectionNotEstablished => e # Handle database connection failure rescue Flipper::Error => e # Handle Flipper-specific error end ``` -------------------------------- ### Actor Gate - Example Usage Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/06-gates.md Demonstrates enabling a feature for specific users and checking if the feature is enabled for individual users or multiple users. ```ruby flipper.enable_actor(:search, user1) flipper.enable_actor(:search, user2) flipper.enabled?(:search) # => false (no actor, gate empty) flipper.enabled?(:search, user1) # => true flipper.enabled?(:search, user2) # => true flipper.enabled?(:search, user3) # => false flipper.enabled?(:search, user1, user2) # => true (any match) ``` -------------------------------- ### Build Flipper App Container with Docker Compose Source: https://github.com/flippercloud/flipper/blob/main/docs/DockerCompose.md Builds the application container using Docker Compose. Ensure Docker Compose is installed. ```bash docker-compose build ``` -------------------------------- ### Run All Tests Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Execute all tests including RSpec, Minitest, and Rails tests. Ensure dependencies are installed via `script/bootstrap`. ```ruby bundle exec rake ``` -------------------------------- ### Add Wrapper Adapters to Flipper Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Adds wrapper adapters to the Flipper adapter stack using the `use` method. This example demonstrates building an instrumented and memoizable adapter stack on top of a Redis adapter. ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/redis' Flipper::Adapters::Redis.new(redis) end config.use Flipper::Adapters::Memoizable config.use Flipper::Adapters::Instrumented end ``` -------------------------------- ### Configure Flipper UI Options Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Customize Flipper UI behavior and text by yielding a configuration object. This example enables breadcrumbs and feature creation. ```ruby Flipper::UI.configure do |config| config.show_breadcrumbs = true config.feature_creation_enabled = true end ``` -------------------------------- ### Set Primary Adapter in Flipper Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Configures the primary adapter for Flipper using a block. This example shows how to set up the ActiveRecord adapter. ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/active_record' Flipper::Adapters::ActiveRecord.new end end ``` -------------------------------- ### Boolean Gate - Example Usage Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/06-gates.md Demonstrates enabling and disabling a feature using the boolean gate and checking its enabled status for any user or without specifying a user. ```ruby flipper.enable(:search) # Boolean gate = true flipper.enabled?(:search, user) # => true for ANY user flipper.enabled?(:search) # => true flipper.disable(:search) # Boolean gate = nil flipper.enabled?(:search) # => false ``` -------------------------------- ### Memoizer Middleware Manual Setup Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Manually set up the Memoizer middleware in a Rack application to cache feature flag checks within a request. ```ruby use Flipper::Middleware::Memoizer ``` -------------------------------- ### Create Adapter-Specific Middleware Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Develop custom middleware that interacts with the Flipper instance, for example, to preload features. This middleware requires the Flipper instance during initialization. ```ruby class CacheWarmerMiddleware def initialize(app, flipper) @app = app @flipper = flipper end def call(env) # Preload common features @flipper.preload([:search, :new_ui, :api_v2]) @app.call(env) end end # Use it: use CacheWarmerMiddleware, Flipper.instance ``` -------------------------------- ### Testing Flipper Features in RSpec Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Set up Flipper for testing within an RSpec environment. This example shows how to enable a feature and assert its state. ```ruby describe "Feature flags" do before do @flipper = Flipper.instance end it "enables feature" do @flipper.enable(:search) expect(@flipper.enabled?(:search)).to be true end end ``` -------------------------------- ### API Response Header Example Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md This snippet shows the expected Content-Type header for JSON responses from the Flipper API. ```text Content-Type: application/json ``` -------------------------------- ### Flipper.new Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Creates a new DSL instance with the given adapter. This is the primary way to initialize Flipper with a specific storage backend. ```APIDOC ## Flipper.new ### Description Creates a new DSL instance with the given adapter. This is the primary way to initialize Flipper with a specific storage backend. ### Signature def new(adapter, options = {}) ### Parameters #### Path Parameters - **adapter** (Flipper::Adapter) - Required - The adapter for storing feature flag state - **options** (Hash) - Optional - Configuration options - **options[:instrumenter]** (Class) - Optional - What to use for instrumentation. Defaults to `Instrumenters::Noop`. - **options[:memoize]** (Boolean) - Optional - Whether to wrap adapter with memoization. Defaults to `true`. ### Returns `Flipper::DSL` instance ### Example ```ruby require 'flipper' require 'flipper/adapters/memory' adapter = Flipper::Adapters::Memory.new flipper = Flipper.new(adapter) flipper.enable(:search) flipper.enabled?(:search) # => true ``` ``` -------------------------------- ### List all features via REST API Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Use curl to send a GET request to the Flipper API endpoint to list all available features. ```bash # List all features curl http://localhost:3000/api/features ``` -------------------------------- ### Adapter Interface: Get All Features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Retrieves all features and their values. Adapters should override this for efficiency; the default implementation calls `features` then `get_multi`. ```ruby def get_all(**kwargs) # Returns Hash of all feature values end ``` -------------------------------- ### Get a specific feature via REST API Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Use curl to send a GET request to the Flipper API endpoint to retrieve details for a specific feature. ```bash # Get one feature curl http://localhost:3000/api/features/search ``` -------------------------------- ### SetupEnv Middleware Usage Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Use the SetupEnv middleware to add the Flipper instance to the Rack environment. This is automatically handled by Flipper::UI.app and Flipper::Api.app. ```ruby use Flipper::Middleware::SetupEnv, flipper, env_key: 'flipper' ``` -------------------------------- ### Adapter Interface: Get Multiple Features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Retrieves gate values for multiple features efficiently. Adapters should override this for performance; the default implementation calls `get` for each feature. ```ruby def get_multi(features) # Returns Hash of feature.key => values end ``` -------------------------------- ### Initialize Redis Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the Redis adapter. This requires the 'flipper-redis' gem and a running Redis instance. ```ruby require 'flipper/adapters/redis' redis = Redis.new adapter = Flipper::Adapters::Redis.new(redis) flipper = Flipper.new(adapter) ``` -------------------------------- ### Gradual rollout of a feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Implement a gradual rollout strategy for a feature by enabling it for increasing percentages of actors over time, starting with a small percentage and monitoring. ```ruby # Day 1: Small percentage Flipper.enable_percentage_of_actors(:new_ui, 5) # Monitor... # Day 3: Expand Flipper.enable_percentage_of_actors(:new_ui, 25) # Day 5: Half Flipper.enable_percentage_of_actors(:new_ui, 50) # Day 7: Everyone Flipper.enable(:new_ui) ``` -------------------------------- ### Custom Rack Protection Options for Flipper UI Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Configure specific Rack::Protection options when creating the Flipper UI app. This example enables authenticity token and frame options protection with custom settings. ```ruby app = Flipper::UI.app(flipper, rack_protection: { use: [:authenticity_token, :frame_options], authenticity_token: :auto, frame_options: :sameorigin }) ``` -------------------------------- ### DSL#initialize Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Initializes a new Flipper DSL instance, requiring an adapter for feature flag storage and accepting optional configuration options like an instrumenter and memoization settings. ```APIDOC ## DSL#initialize(adapter, options = {}) ### Description Initialize a new DSL instance. ### Signature ```ruby def initialize(adapter, options = {}) ``` ### Parameters #### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | adapter | Flipper::Adapter | yes | — | Feature flag storage adapter | | options | Hash | no | {} | Configuration options | | options[:instrumenter] | Class | no | Instrumenters::Noop | Instrumentation class | | options[:memoize] | Boolean | no | true | Enable memoization | ``` -------------------------------- ### Feature#expression_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the expression value for the feature. ```APIDOC ## Feature#expression_value ### Description Get the expression value. ### Response #### Success Response - **(Hash | nil)** ``` -------------------------------- ### Custom Instrumenter Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Set a custom instrumenter for monitoring Flipper operations. This example defines a basic instrumenter that logs event durations. ```ruby Flipper.configure do |config| config.default do Flipper.new(adapter, instrumenter: MyInstrumenter) end end ``` ```ruby class MyInstrumenter def instrument(event_name, payload = {}) start_time = Time.now yield(payload) if block_given? duration = Time.now - start_time puts "#{event_name} took #{duration}ms" end end ``` ```ruby { feature_name: "search", operation: :enabled?, gate_name: :boolean, result: true, thing: nil, actors: [actor], feature: Feature instance } ``` -------------------------------- ### Feature#percentage_of_time_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the percentage of time for which the feature is enabled. ```APIDOC ## Feature#percentage_of_time_value ### Description Get the percentage of time value. ### Response #### Success Response - **(Integer | nil)** - Percentage 0-100 ``` -------------------------------- ### Setup Flipper API Middleware Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md Include the Flipper API middleware in your Rails routes or as a standalone Rack application. Ensure Flipper and flipper-api gems are required. ```ruby require 'flipper' require 'flipper-api' # In Rails config/routes.rb: Rails.application.routes.draw do mount Flipper::Api.app => '/flipper/api' end # Or standalone Rack: app = Flipper::Api.app(flipper_instance) ``` -------------------------------- ### Feature#percentage_of_actors_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the percentage of actors for whom the feature is enabled. ```APIDOC ## Feature#percentage_of_actors_value ### Description Get the percentage of actors value. ### Response #### Success Response - **(Integer | nil)** - Percentage 0-100 ``` -------------------------------- ### Initialize PStore Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the PStore adapter for file-based persistence. Specify the path to the .pstore file. ```ruby adapter = Flipper::Adapters::PStore.new('features.pstore') ``` -------------------------------- ### Protect Flipper UI with Authentication Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Secure the Flipper UI by adding an authentication check. This example redirects non-admin users to the root path. ```ruby mount Flipper::UI.app => '/flipper' do match '*path', to: redirect("/") unless current_user&.admin?, via: [:get, :post, :delete] end ``` -------------------------------- ### Initialize Flipper DSL Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Initialize a new Flipper::DSL instance with a required adapter and optional configuration options like instrumentation and memoization. ```ruby def initialize(adapter, options = {}) # ... implementation details ... end ``` -------------------------------- ### Feature#groups_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the set of groups for whom the feature is enabled. ```APIDOC ## Feature#groups_value ### Description Get all groups enabled for this feature. ### Response #### Success Response - **Set** - Set of group names ``` -------------------------------- ### Get All Known Features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Retrieves all features currently known by the Flipper adapter. Returns a Set of Flipper::Feature instances. ```ruby def features adapter.features.map { |name| feature(name) }.to_set end ``` -------------------------------- ### Feature#actors_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the set of actors for whom the feature is enabled. ```APIDOC ## Feature#actors_value ### Description Get all actors enabled for this feature. ### Response #### Success Response - **Set** - Set of actor flipper_id strings ``` -------------------------------- ### RSpec Examples for Feature Flag Testing with Actors Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/10-actors.md Demonstrates how to test feature flags in RSpec using different enablement strategies: fully enabled, expression-based, and actor-specific. ```ruby describe "Feature flags" do let(:admin_user) { Flipper::Actor.new("admin_1", { role: "admin" }) } let(:regular_user) { Flipper::Actor.new("user_1", { role: "user" }) } before do Flipper.enable(:admin_panel) end it "enables admin panel for everyone when fully enabled" do expect(Flipper.enabled?(:admin_panel, admin_user)).to be true expect(Flipper.enabled?(:admin_panel, regular_user)).to be true end it "enables admin panel for admins only" do Flipper.disable(:admin_panel) Flipper.enable_expression(:admin_panel, Flipper.property(:role).eq("admin")) expect(Flipper.enabled?(:admin_panel, admin_user)).to be true expect(Flipper.enabled?(:admin_panel, regular_user)).to be false end it "enables admin panel for specific actors" do Flipper.disable(:admin_panel) Flipper.enable_actor(:admin_panel, admin_user) expect(Flipper.enabled?(:admin_panel, admin_user)).to be true expect(Flipper.enabled?(:admin_panel, regular_user)).to be false end end ``` -------------------------------- ### Feature#boolean_value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Gets the boolean gate value for the feature. ```APIDOC ## Feature#boolean_value ### Description Get the boolean gate value. ### Response #### Success Response - **(true | false | nil)** ``` -------------------------------- ### Initialize Flipper Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Creates a new Flipper configuration instance. Automatically sets up a Memory adapter as the default. ```ruby config = Flipper::Configuration.new ``` -------------------------------- ### Get one feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Retrieve the status and configuration for a specific feature. ```APIDOC ## Get one feature ### Description Retrieve the status and configuration for a specific feature. ### Method ```bash curl http://localhost:3000/api/features/search ``` ``` -------------------------------- ### Initialize ActiveRecord Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the ActiveRecord adapter. This requires the 'flipper-active_record' gem and database migrations to be run. ```ruby require 'flipper/adapters/active_record' adapter = Flipper::Adapters::ActiveRecord.new flipper = Flipper.new(adapter) ``` -------------------------------- ### Feature#initialize Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Initializes a new Feature instance with a name, adapter, and optional configuration. ```APIDOC ## Feature#initialize(name, adapter, options = {}) ### Description Initialize a new Feature instance. ### Parameters #### Path Parameters - **name** (String, Symbol) - Required - Feature name - **adapter** (Flipper::Adapter) - Required - Storage adapter - **options** (Hash) - Optional - Configuration options - **options[:instrumenter]** (Class) - Optional - Instrumentation class ``` -------------------------------- ### Redis Adapter with Caching Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Configure the Redis adapter to use a cache store for improved performance. This example shows how to integrate Rails.cache with the Redis adapter. ```ruby config.use Flipper::Adapters::RedisCached, redis: redis_client, cache_store: Rails.cache ``` -------------------------------- ### Export All Features to String and File Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/11-import-export-serialization.md Demonstrates exporting all Flipper features to a string and then writing that string to a file. Also shows how to gzip the export for compressed storage. ```Ruby # To string export_contents = Flipper.export.contents # To file File.write("features.json", Flipper.export.contents) # With gzip compression compressed = Zlib.gzip(Flipper.export.contents) File.write("features.json.gz", compressed) ``` -------------------------------- ### Initialize Memory Adapter with Options Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the in-memory adapter with optional source and threadsafe configurations. Thread safety is enabled by default. ```ruby adapter = Flipper::Adapters::Memory.new(source: nil, threadsafe: true) ``` -------------------------------- ### Get Feature Key Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the adapter-safe string representation of the feature name. ```ruby attr_reader :key ``` -------------------------------- ### Testing Memoizer Middleware with Rack::Test Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Verify the behavior of Flipper's Memoizer middleware using Rack::Test. This setup includes the Memoizer and SetupEnv middleware in a Rack builder. ```ruby require 'rack/test' describe Flipper::Middleware::Memoizer do include Rack::Test::Methods def app builder = Rack::Builder.new do use Flipper::Middleware::Memoizer use Flipper::Middleware::SetupEnv, Flipper.instance run ->(env) { [200, {}, ["OK"]] } end builder.to_app end it "memoizes during request" do get "/" expect(last_response.status).to eq 200 end end ``` -------------------------------- ### Get Feature Name Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the name of the feature. The name can be a String or a Symbol. ```ruby attr_reader :name ``` -------------------------------- ### Get Disabled Groups for Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves a set of groups that are not enabled for this feature. ```ruby def disabled_groups ``` ``` -------------------------------- ### Custom Organization Actor Implementation Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/10-actors.md Example of a custom `Organization` class implementing `flipper_id` and `flipper_properties`. This enables Flipper to evaluate feature flags based on organization attributes. ```ruby class Organization def initialize(id, name, plan) @id = id @name = name @plan = plan end def flipper_id "org_#{@id}" end def flipper_properties { name: @name, plan: @plan, member_count: members.count } end end ``` -------------------------------- ### Promote Flipper State from Staging to Production Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/11-import-export-serialization.md Demonstrates promoting feature flag configurations from a staging environment to a production environment. This involves exporting from staging and then importing into production. ```Ruby # In staging environment staging_flipper = Flipper.new(staging_adapter) # Export current state staging_export = staging_flipper.export # Import to production production_flipper = Flipper.new(production_adapter) production_flipper.import(staging_export) ``` -------------------------------- ### Get Group Instance Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Retrieve a group instance by its name using the `group` method. ```ruby def group(name) Flipper.group(name) end ``` -------------------------------- ### Gradual Rollout with Percentage of Actors Gate Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/06-gates.md Demonstrates a common gradual rollout pattern using the percentage of actors gate, increasing the percentage over time before enabling for everyone. ```ruby # Day 1: 5% of actors flipper.enable_percentage_of_actors(:new_ui, 5) # Day 3: 25% of actors flipper.enable_percentage_of_actors(:new_ui, 25) # Day 5: 50% of actors flipper.enable_percentage_of_actors(:new_ui, 50) # Ready: Enable for everyone flipper.enable(:new_ui) ``` -------------------------------- ### Custom User Actor Implementation Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/10-actors.md Example of a custom `User` class implementing `flipper_id` and `flipper_properties` for use with Flipper. This allows Flipper to evaluate feature flags against user-specific attributes. ```ruby class User attr_reader :id, :email, :plan, :team_size def initialize(id, email, plan: "free", team_size: 1) @id = id @email = email @plan = plan @team_size = team_size end # Required for Flipper def flipper_id "user_#{id}" end # Optional but recommended for expressions def flipper_properties { email: email, plan: plan, team_size: team_size, signed_up_at: created_at.iso8601 } end end # Usage user = User.new(123, "alice@example.com", plan: "premium", team_size: 50) Flipper.enable_actor(:new_ui, user) Flipper.enabled?(:new_ui, user) # => true ``` -------------------------------- ### Get Enabled Groups for Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves a set of groups that are currently enabled for this feature. ```ruby def enabled_groups ``` ``` -------------------------------- ### Query Feature States Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Get the current state and enabled gates for a Flipper feature. ```ruby feature = Flipper.feature(:search) feature.on? # => true if fully enabled feature.off? # => true if disabled feature.conditional? # => true if partially enabled feature.state # => :on, :off, or :conditional feature.enabled_gates # => which gates are active ``` -------------------------------- ### Default Rack Protection in Flipper UI Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md The Flipper UI automatically includes Rack::Protection middleware for security. This example shows the default authenticity token protection. ```ruby builder.use Rack::Protection::AuthenticityToken ``` -------------------------------- ### Gradual Rollout with Cutoff Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/09-expressions.md Enables a feature for the first 100,000 users who signed up on or after January 1st, 2024. ```ruby flipper.enable_expression(:new_ui, Flipper.all( Flipper.property(:user_id).lte(100000), # First 100k users Flipper.property(:signup_date).gte(Flipper.time("2024-01-01")) )) ``` -------------------------------- ### Memoizer Middleware Usage Example Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Demonstrates how the Memoizer middleware improves performance by caching feature flag checks within the same request. Subsequent calls to Flipper.enabled? for the same feature use the memoized value. ```ruby # In a Rails action if Flipper.enabled?(:search) # First check, evaluates @has_search = true end if Flipper.enabled?(:search) # Second check in same request, uses memoized value @still_has_search = true end ``` -------------------------------- ### Feature#groups Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md An alias for `enabled_groups`, providing an alternative way to get the enabled groups for this feature. ```APIDOC ## Feature#groups ### Description Alias for `enabled_groups`. ### Method ```ruby alias_method :groups, :enabled_groups ``` ``` -------------------------------- ### Configuration#use Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Adds a wrapper adapter to the Flipper configuration. This allows for chaining adapters to modify or enhance existing ones. ```APIDOC ## Configuration#use ### Description Add a wrapper adapter. ### Signature ```ruby def use(klass, *args, **kwargs, &block) @builder.use(klass, *args, **kwargs, &block) end ``` ### Example ```ruby Flipper.configure do |config| config.adapter do Flipper::Adapters::Memory.new end config.use Flipper::Adapters::Memoizable config.use Flipper::Adapters::Instrumented end ``` ``` -------------------------------- ### Get Groups Enabled for Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves a set of all group names that are explicitly enabled for this feature. ```ruby def groups_value ``` -------------------------------- ### Get Actors Enabled for Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves a set of all actor flipper_ids that are explicitly enabled for this feature. ```ruby def actors_value ``` -------------------------------- ### Flipper.configure Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Configure Flipper globally with a block. This allows setting up the adapter and other configurations that will be used by default. ```APIDOC ## Flipper.configure ### Description Configure Flipper globally with a block. This allows setting up the adapter and other configurations that will be used by default. ### Signature def configure yield configuration if block_given? end ### Parameters #### Path Parameters - **block** (Proc) - Optional - Yields a Configuration instance ### Example ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/active_record' Flipper::Adapters::ActiveRecord.new end end # Now Flipper.instance uses the ActiveRecord adapter Flipper.enabled?(:search) ``` ``` -------------------------------- ### GET /features/:feature_name Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md Retrieves a single feature by its name. Optionally excludes gate details. ```APIDOC ## GET /features/:feature_name ### Description Get a single feature. ### Method GET ### Endpoint /features/:feature_name ### Parameters #### Path Parameters - **feature_name** (string) - The name of the feature to retrieve. #### Query Parameters - **exclude_gates** (Boolean) - Optional - Exclude gate details (default: false) ### Response #### Success Response (200 OK) - **key** (String) - The name of the feature. - **state** (String) - The current state of the feature. - **gates** (Array) - An array of gate objects associated with the feature. #### Error Response (404 Not Found) - **error** (String) - "feature_not_found" - **message** (String) - "Feature not found" ### Request Example ```bash curl http://localhost:3000/flipper/api/features/search ``` ``` -------------------------------- ### Create New Flipper DSL Instance Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Use Flipper.new to create a new DSL instance with a specified adapter and optional configuration. The adapter is required for storing feature flag state. ```ruby require 'flipper' require 'flipper/adapters/memory' adapter = Flipper::Adapters::Memory.new flipper = Flipper.new(adapter) flipper.enable(:search) flipper.enabled?(:search) # => true ``` -------------------------------- ### Get All Registered Group Names Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Flipper.group_names returns a set of symbols representing the names of all registered groups. ```ruby Flipper.group_names ``` -------------------------------- ### Get All Registered Groups Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Flipper.groups returns a set of all currently registered Flipper::Types::Group instances. ```ruby Flipper.groups ``` -------------------------------- ### Flipper.configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Returns the global configuration instance. This object holds the settings defined via `Flipper.configure`. ```APIDOC ## Flipper.configuration ### Description Returns the global configuration instance. This object holds the settings defined via `Flipper.configure`. ### Signature def configuration @configuration ||= Configuration.new end ### Returns `Flipper::Configuration` instance ``` -------------------------------- ### Configure Primary Adapter with Block Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Configure the primary adapter for Flipper using a block. This allows for dynamic adapter initialization within the Flipper configuration. ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/active_record' Flipper::Adapters::ActiveRecord.new end end ``` -------------------------------- ### Get Disabled Gates for a Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves an array of Flipper::Gate instances that are currently disabled for this feature. ```ruby def disabled_gates ``` -------------------------------- ### Get Currently Enabled Gates Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves an array of Flipper::Gate instances that are currently enabled for this feature. ```ruby def enabled_gates ``` ``` -------------------------------- ### GET /features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md Retrieves all features or specific features by their names. Supports filtering and excluding gate details. ```APIDOC ## GET /features ### Description Get all features or specific ones by name. ### Method GET ### Endpoint /features ### Parameters #### Query Parameters - **keys** (String) - Optional - Comma-separated list of feature names to fetch - **exclude_gates** (Boolean) - Optional - Exclude gate details (default: false) - **exclude_gate_names** (Boolean) - Optional - Exclude gate names (default: false) ### Response #### Success Response (200 OK) - **features** (Array) - An array of feature objects. Each feature object contains: - **key** (String) - The name of the feature. - **state** (String) - The current state of the feature (e.g., "on", "off"). - **gates** (Array) - An array of gate objects associated with the feature. - **gates_as_json** (Array) - An array of gate objects in JSON format. ### Request Example ```bash # Get all features curl http://localhost:3000/flipper/api/features # Get specific features curl http://localhost:3000/flipper/api/features?keys=search,new_ui # Exclude gate details curl http://localhost:3000/flipper/api/features?exclude_gates=true ``` ``` -------------------------------- ### Run ActiveRecord Migrations Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Run the necessary database migrations for the ActiveRecord adapter to create the required tables. ```bash bin/rails flipper_ui:install ``` -------------------------------- ### Get Single Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md Retrieve details for a single feature by its name. Gate details can be excluded from the response. ```bash curl http://localhost:3000/flipper/api/features/search ``` -------------------------------- ### Preload All Features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md The `preload_all` method fetches all features available in the adapter, returning an array of `Flipper::Feature` instances. ```ruby def preload_all keys = @adapter.get_all.keys keys.map { |key| feature(key) } end ``` -------------------------------- ### Adapter Interface: Get Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Retrieves the gate values for a specific feature. This method is required for all adapters. ```ruby def get(feature) # Returns Hash with gate values end ``` -------------------------------- ### Set Default Flipper Instance with Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Configure a default Flipper DSL instance using `config.default` within `Flipper.configure`. This is useful for setting up a specific Flipper instance with a chosen adapter for the application. ```ruby Flipper.configure do |config| config.default do Flipper.new(Flipper::Adapters::Memory.new) end end ``` -------------------------------- ### Configure Flipper with Wrapper Adapters Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Configure Flipper with a primary adapter and additional wrapper adapters like Memoizable or Instrumented. ```ruby Flipper.configure do |config| config.adapter do Flipper::Adapters::Redis.new(Redis.new) end config.use Flipper::Adapters::Memoizable config.use Flipper::Adapters::Instrumented end ``` -------------------------------- ### Sequel Adapter Configuration Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Configure Flipper to use the Sequel adapter. ```ruby require 'flipper/adapters/sequel' Flipper.configure do |config| config.adapter { Flipper::Adapters::Sequel.new(DB) } end ``` -------------------------------- ### expression(name) Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Gets the expression for a given feature name. Returns Flipper::Expression or nil if the feature does not exist. ```APIDOC ## expression(name) ### Description Gets the expression for a given feature name. Returns Flipper::Expression or nil if the feature does not exist. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the feature ### Response #### Success Response - Returns: `Flipper::Expression` or `nil` ``` -------------------------------- ### Initialize Memory Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the in-memory adapter for testing or development. It requires no external dependencies. ```ruby adapter = Flipper::Adapters::Memory.new flipper = Flipper.new(adapter) ``` -------------------------------- ### Get Names of Enabled Gates Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves an array of symbols representing the names of the gates currently enabled for this feature. ```ruby def enabled_gate_names ``` ``` -------------------------------- ### Manual Fallback for Local Releases Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Execute a manual release process locally. This command will prompt for One-Time Password (OTP) if needed. ```ruby script/release ``` -------------------------------- ### Handle TypeError for Feature Name Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Example of triggering and fixing a TypeError when a non-String or non-Symbol is used as a feature name. ```ruby flipper.enabled?(123) # => ArgumentError: 123 must be a String or Symbol flipper.enabled?("search") # Use String or Symbol ``` -------------------------------- ### Trigger InvalidConfigurationValue and ArgumentError Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Shows examples of triggering Flipper::InvalidConfigurationValue and ArgumentError due to invalid configuration values. ```ruby Flipper::Types::PercentageOfActors.new(150) # => ArgumentError: value must be a positive number less than or equal to 100, but was 150 # Or in configuration: Flipper.configure do |config| config.invalid_option = "value" end ``` -------------------------------- ### Initialize Failover Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Initialize the Failover adapter to switch between primary and secondary adapters on failure. Both adapters must be initialized first. ```ruby primary = Flipper::Adapters::Redis.new(redis) secondary = Flipper::Adapters::Memory.new failover = Flipper::Adapters::Failover.new(primary, secondary) flipper = Flipper.new(failover) ``` -------------------------------- ### Get Adapter Stack String Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md The `adapter_stack` method returns a string representation of the full adapter chain, useful for debugging. ```ruby def_delegators :@adapter, :adapter_stack ``` ```ruby puts flipper.adapter_stack # => "memoizable -> memory" ``` -------------------------------- ### Configure Flipper Globally Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Use Flipper.configure with a block to set up Flipper globally. The block yields a Configuration instance, allowing you to specify the adapter and other options. ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/active_record' Flipper::Adapters::ActiveRecord.new end end # Now Flipper.instance uses the ActiveRecord adapter Flipper.enabled?(:search) ``` -------------------------------- ### Get Disabled Gate Names for a Feature Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves an array of symbols representing the names of gates that are currently disabled for this feature. ```ruby def disabled_gate_names ``` -------------------------------- ### preload_all Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Preloads all features from the adapter and returns an array of Flipper::Feature instances. ```APIDOC ## preload_all ### Description Preloads all features from the adapter and returns an array of Flipper::Feature instances. ### Response #### Success Response - Returns: `Array` of `Flipper::Feature` instances ``` -------------------------------- ### Get Expression Value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the expression used for conditional feature enablement. Returns a hash representing the expression or nil. ```ruby def expression_value ``` -------------------------------- ### Enable StatSD Metrics Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Configure Flipper to emit metrics using the StatsD client. Ensure a StatsD client is initialized and passed to the configuration. ```ruby Flipper.configure do |config| statsd = StatsD.new config.statsd = statsd end ``` -------------------------------- ### Get Percentage of Time Value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the configured percentage of time for which the feature is enabled. Returns an integer between 0-100 or nil. ```ruby def percentage_of_time_value ``` -------------------------------- ### Initialize Feature Instance Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Initializes a new Feature instance with a name, adapter, and optional configuration. The adapter handles storage, and an instrumenter can be provided for monitoring. ```ruby def initialize(name, adapter, options = {}) end ``` -------------------------------- ### Get Percentage of Actors Value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the configured percentage of actors for which the feature is enabled. Returns an integer between 0-100 or nil. ```ruby def percentage_of_actors_value ``` -------------------------------- ### Get All or Specific Features Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/07-rest-api-endpoints.md Retrieve a list of all features or filter by a comma-separated list of feature names. Gate details can be excluded. ```bash # Get all features curl http://localhost:3000/flipper/api/features # Get specific features curl http://localhost:3000/flipper/api/features?keys=search,new_ui # Exclude gate details curl http://localhost:3000/flipper/api/features?exclude_gates=true ``` -------------------------------- ### Get Flipper::Actor Properties Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/10-actors.md Retrieves the properties hash for the actor, used for expression evaluation and property-based feature gates. ```ruby attr_reader :flipper_properties ``` ```ruby actor = Flipper::Actor.new("user_123", { plan: "premium", team_size: 50 }) actor.flipper_properties # => { plan: "premium", team_size: 50 } ``` -------------------------------- ### Gzip Compression Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Use `Flipper::Typecast.to_gzip` for compressing strings with gzip. This is preferred over direct `Zlib` usage. ```ruby Typecast.to_gzip(string) ``` -------------------------------- ### HTTP Client Configuration Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Use `Flipper::Adapters::Http::Client` for outbound HTTP requests. It includes features like timeouts, retries, and SSL verification. ```ruby Flipper::Adapters::Http::Client ``` -------------------------------- ### Get Boolean Gate Value Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the specific boolean gate value for the feature. Returns true, false, or nil if not set. ```ruby def boolean_value ``` -------------------------------- ### Get Flipper::Actor ID Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/10-actors.md Retrieves the unique identifier for the actor. This is used for actor gate lookups, percentage hashing, and identification. ```ruby attr_reader :flipper_id ``` ```ruby actor = Flipper::Actor.new("user_123") actor.flipper_id # => "user_123" ``` -------------------------------- ### Troubleshooting actor matching Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Ensure that actors used with Flipper respond to the `flipper_id` method. Provide an example for a custom actor object. ```ruby # Ensure actor responds to flipper_id actor = Flipper::Actor.new("user_123") Flipper.enabled?(:feature, actor) # For custom objects class User def flipper_id "user_".to_s + id.to_s end end ``` -------------------------------- ### Standalone Flipper UI Rack App Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Set up a standalone Flipper UI application using Rack. Ensure Flipper and Flipper-UI gems are required. ```ruby require 'flipper' require 'flipper-ui' app = Flipper::UI.app(flipper_instance) run app ``` -------------------------------- ### Using Flipper::Actor Wrapper Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/06-gates.md Demonstrates how to use the `Flipper::Actor` wrapper to provide an actor with properties for Flipper evaluation when a custom actor class is not defined or suitable. ```ruby actor = Flipper::Actor.new("user_1", { plan: "premium" }) flipper.enabled?(:new_api, actor) ``` -------------------------------- ### Run All Tests (script) Source: https://github.com/flippercloud/flipper/blob/main/CLAUDE.md Bootstrap dependencies and run tests across multiple Rails versions (5.0-8.0). This provides a comprehensive test suite. ```bash script/test ``` -------------------------------- ### Get Feature Expression Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md The `expression` method returns the `Flipper::Expression` object associated with a given feature name, or `nil` if none exists. ```ruby def expression(name) feature(name).expression end ``` -------------------------------- ### Access Flipper in Rack Environment Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/08-ui-and-middleware.md Make the Flipper DSL instance available in the Rack environment for use in controllers and views. This is typically set up by the Flipper middleware. ```ruby # In a Rack handler env['flipper'] # => Flipper::DSL instance ``` ```ruby class ApplicationController < ActionController::Base def flipper @flipper ||= env['flipper'] end helper_method :flipper end ``` ```erb <% if flipper.enabled?(:new_ui) %> <%= render 'new_ui' %> <% else %> <%= render 'old_ui' %> <% end %> ``` -------------------------------- ### Get Feature State Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/02-feature-class.md Retrieves the current state of the feature, which can be :on, :off, or :conditional. This method provides a high-level overview of the feature's enablement status. ```ruby feature.state ``` -------------------------------- ### adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/01-core-dsl.md Provides access to the underlying adapter instance. ```APIDOC ## adapter ### Description Provides access to the underlying adapter instance. ### Response #### Success Response - Returns: The adapter instance ``` -------------------------------- ### Percentage Rollout Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/00-quick-reference.md Enable a feature for a percentage of actors or a percentage of time. ```ruby Flipper.enable_percentage_of_actors(:new_ui, 25) # 25% of actors Flipper.enable_percentage_of_time(:experiment, 50) # 50% of the time ``` -------------------------------- ### Configure Flipper with Redis Adapter Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/05-configuration-errors.md Sets up Flipper to use a Redis adapter globally. After this configuration, all Flipper calls will interact with Redis. ```ruby Flipper.configure do |config| config.adapter do require 'flipper/adapters/redis' Flipper::Adapters::Redis.new(Redis.new) end end # Now all Flipper calls use Redis: Flipper.enabled?(:search) Flipper.enable(:search) ``` -------------------------------- ### Adapter Interface: Adapter Stack Source: https://github.com/flippercloud/flipper/blob/main/_autodocs/04-adapters.md Returns a string representing the full chain of adapters, useful for debugging wrapper configurations. ```ruby def adapter_stack # Returns String showing wrapper chain end ```