🐬
(Nel mondo Ruby/Rails)
# Gemfile
gem 'ruby_flipper'
# config/features.rb
feature :new_header, Figaro.env.new_header
feature :redwood_checkout do |params, session|
percentage_of_traffic = Figaro.env.redwood_checkout_traffic_percentage.to_i
session[:checkout_version] = case
when params[:redwood] == 'true'
'redwood'
when params[:redwood] == 'false'
'control'
when session[:checkout_version]
session[:checkout_version]
when (rand(100) < percentage_of_traffic)
'redwood'
else
'control'
end
next session[:checkout_version] == 'redwood'
end
# any application file
if feature_active?(:new_header)
#.. do magic things
end
gem 'flipper'
gem 'flipper-redis'
gem 'flipper-ui'
# config/features.rb
Flipper.configure do |config|
config.default do
client = Redis.new
adapter = Flipper::Adapters::Redis.new(client)
flipper = Flipper.new(adapter)
end
end
# config/routes.rb
YourRailsApp::Application.routes.draw do
mount Flipper::UI.app(Flipper) => '/flipper'
end
# any application file
if Flipper.enabled?(:search)
puts 'Search away!'
else
puts 'No search for you!'
end