This is simple wrapper around Flipper for Rails projects to remove ugly global variables like $flipper
.
ffeature?(feature, user = current_user)
helper in views and controllersFFeature.enabled?(feature, user)
helper for PORO
In case user
or current_user
responds to #tester?
and returns true
it will be registered in testers
Flipper group. For that group all features defined in FFeature.features
will be enabled by default.
You can configure FFeature
in config/inititalizers/ffeature.rb
# config/inititalizers/ffeature.rb
require "flipper"
require "flipper/adapters/redis"
url = ENV.fetch("REDISTOGO_URL", ENV.fetch("REDIS_URL", nil))
url = URI.parse(url) if url.present?
redis = Redis.new(url: url)
adapter = Flipper::Adapters::Redis.new(redis)
FFeature.configure do |config|
config.features = %i(user_management)
config.ip_whitelist = ENV.fetch("FLIPPER_UI_IP_WHITELIST", "").split(",")
config.flipper = Flipper.new(adapter)
config.dev_mode = ENV["FEATURE_DEV_MODE"].present?
end
Following options are available:
features
– list of features registered and enabled by default for testers.ip_whitelist
– list of IP addresses, could be used to configure FlipperUI route constraintsdev_mode
– if enabled all features considered enabled for all users
You can use FlipperUI to have more robust control over features.
# config/routes.rb
constraints(->(request) { FFeature.ip_allowed?(request.remote_ip) }) do
mount Flipper::UI.app(FFeature.flipper) => "/flipper"
end
FFeature is maintained and was written by Flatstack with the help of our contributors.