Configuration
Advanced configuration options for customizing Flagstack in your application.
Basic Configuration
The simplest configuration only requires your API token. With FLAGSTACK_TOKEN set, Flagstack auto-configures:
# Auto-configures when FLAGSTACK_TOKEN is set
# Or configure explicitly:
Flagstack.configure do |config|
config.token = ENV["FLAGSTACK_TOKEN"]
end
Local Caching with ActiveRecord
For persistent local storage, use ActiveRecord. Flagstack auto-detects this when flipper-active_record is installed. Or configure explicitly:
Flagstack.configure do |config|
config.token = ENV["FLAGSTACK_TOKEN"]
# Explicitly set ActiveRecord adapter for local storage
config.local_adapter = Flipper::Adapters::ActiveRecord.new
end
Sync Interval
By default, Flagstack syncs flag states every 10 seconds. You can customize this (minimum 10 seconds):
Flagstack.configure do |config|
config.token = ENV["FLAGSTACK_TOKEN"]
config.sync_interval = 30 # seconds (minimum: 10)
end
Environment-Specific Configuration
Use different tokens for different environments. Token prefixes indicate the environment:
# Token prefixes: fs_live_ (production), fs_test_ (staging),
# fs_dev_ (development), fs_personal_ (personal)
Flagstack.configure do |config|
config.token = case Rails.env
when "production"
ENV["FLAGSTACK_PRODUCTION_TOKEN"]
when "staging"
ENV["FLAGSTACK_STAGING_TOKEN"]
else
ENV["FLAGSTACK_DEVELOPMENT_TOKEN"]
end
end
Tip
Each API token is scoped to a specific environment in Flagstack. Use different tokens to fetch flag states for different environments.
Disable in Test Environment
For tests, skip Flagstack configuration and use Flipper directly with an in-memory adapter:
unless Rails.env.test?
Flagstack.configure do |config|
config.token = ENV["FLAGSTACK_TOKEN"]
end
end
In your test helper, reset Flagstack and use Flipper directly:
RSpec.configure do |config|
config.before(:each) do
Flagstack.reset!
Flipper.instance = Flipper.new(Flipper::Adapters::Memory.new)
end
end