Conditionally roll out features with redis.
gem install feature_flags
Initialize a feature_flags object. I assign it to a global var.
# Usage: FeatureFlags.new(redis, namespace, group_size) $redis = Redis.new $feature_flags = FeatureFlags.new($redis, 'namespace', 100_000)
A city can have a feature in two states. Beta / Live. To check the state of a feature in a city, returns 'live' / 'beta' / 'inactive' $feature_flags.city_state(feature: :<feature>, city_id: <city_id>) To make a feature live for a city $feature_flags.activate_city(feature: :<feature>, city_id: <city_id>, live: true) To make a feature beta for a city $feature_flags.activate_city(feature: :<feature>, city_id: <city_id>, live: false) To deactivate a city (make a feature non-existent for that city) $feature_flags.deactivate_city(feature: :<feature>, city_id: <city_id>) You can obtain a list of features with their states for a city as follows $feature_flags.city_features(city_id: <city_id>, feature_list: [:cashless, :betauser, :non_existent_feature]) returns a hash { cashless: 'live', betauser: 'beta', non_existent_feature: nil }
A user can either be activated / deactivated state for each feature. Feature State User Active? Whitelist Blacklist Live Yes No No Live No No Yes Beta Yes Yes No Beta No No No Non-Existent Always No No No To activate a feature for the user $feature_flags.activate_user(feature: :<feature>, city_id: <city_id>, id: <user_id>) To deactivate a feature for the user $feature_flags.deactivate_user(feature: :<feature>, city_id: <city_id>, id: <user_id>) To check whether a user is active for a feature, returns true / false $feature_flags.user_active?(feature: :<feature>, city_id: <city_id>, id: <user_id>) You can obtain a list of features for a user as follows $feature_flags.user_features(id: <user_id>, city_id: <city_id>, feature_list: [:cashless, :betauser, :non_existent_feature]) returns a hash { cashless: true, betauser: false, non_existent_feature: false }
Copyright © 2015 Althaf Hameez See LICENSE for details.