Class: FeatureCreep::RedisDataStore
- Inherits:
-
Object
- Object
- FeatureCreep::RedisDataStore
- Defined in:
- lib/feature_creep/version.rb,
lib/feature_creep/redis_data_store.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #activate_agent_id(feature, agent_id) ⇒ Object
-
#activate_globally(feature) ⇒ Object
Activate Methods.
- #activate_percentage(feature, percentage) ⇒ Object
- #activate_scope(feature, scope) ⇒ Object
- #active_agent_ids(feature) ⇒ Object
-
#active_global_features ⇒ Object
Reporting Methods.
-
#active_globally?(feature) ⇒ Boolean
Boolean Methods.
- #active_percentage(feature) ⇒ Object
- #active_scopes(feature) ⇒ Object
- #add_feature(feature) ⇒ Object
- #agent_id_active?(feature, agent_id) ⇒ Boolean
- #agent_id_within_active_percentage?(feature, agent_id) ⇒ Boolean
- #deactivate_agent_id(feature, agent_id) ⇒ Object
- #deactivate_all(feature) ⇒ Object
-
#deactivate_globally(feature) ⇒ Object
Deactivate Methods.
- #deactivate_percentage(feature) ⇒ Object
- #deactivate_scope(feature, scope) ⇒ Object
-
#features ⇒ Object
Utility Methods.
-
#initialize(datastore = nil, key_prefix = "feature_creep") ⇒ RedisDataStore
constructor
A new instance of RedisDataStore.
- #remove_feature(feature) ⇒ Object
Constructor Details
#initialize(datastore = nil, key_prefix = "feature_creep") ⇒ RedisDataStore
Returns a new instance of RedisDataStore.
4 5 6 7 |
# File 'lib/feature_creep/redis_data_store.rb', line 4 def initialize(datastore = nil, key_prefix = "feature_creep") @key_prefix = key_prefix @redis = datastore || Redis.new end |
Instance Method Details
#activate_agent_id(feature, agent_id) ⇒ Object
18 19 20 |
# File 'lib/feature_creep/redis_data_store.rb', line 18 def activate_agent_id(feature, agent_id) @redis.sadd(agent_id_key(feature), agent_id) end |
#activate_globally(feature) ⇒ Object
Activate Methods
10 11 12 |
# File 'lib/feature_creep/redis_data_store.rb', line 10 def activate_globally(feature) @redis.sadd(global_key, feature) end |
#activate_percentage(feature, percentage) ⇒ Object
22 23 24 |
# File 'lib/feature_creep/redis_data_store.rb', line 22 def activate_percentage(feature, percentage) @redis.set(percentage_key(feature), percentage) end |
#activate_scope(feature, scope) ⇒ Object
14 15 16 |
# File 'lib/feature_creep/redis_data_store.rb', line 14 def activate_scope(feature, scope) @redis.sadd(scope_key(feature), scope) end |
#active_agent_ids(feature) ⇒ Object
59 60 61 |
# File 'lib/feature_creep/redis_data_store.rb', line 59 def active_agent_ids(feature) @redis.smembers(agent_id_key(feature)) end |
#active_global_features ⇒ Object
Reporting Methods
51 52 53 |
# File 'lib/feature_creep/redis_data_store.rb', line 51 def active_global_features (@redis.smembers(global_key) || []).map(&:to_sym) end |
#active_globally?(feature) ⇒ Boolean
Boolean Methods
68 69 70 |
# File 'lib/feature_creep/redis_data_store.rb', line 68 def active_globally?(feature) @redis.sismember(global_key, feature) end |
#active_percentage(feature) ⇒ Object
63 64 65 |
# File 'lib/feature_creep/redis_data_store.rb', line 63 def active_percentage(feature) @redis.get(percentage_key(feature)) end |
#active_scopes(feature) ⇒ Object
55 56 57 |
# File 'lib/feature_creep/redis_data_store.rb', line 55 def active_scopes(feature) @redis.smembers(scope_key(feature)) || [] end |
#add_feature(feature) ⇒ Object
87 88 89 |
# File 'lib/feature_creep/redis_data_store.rb', line 87 def add_feature(feature) @redis.sadd(@key_prefix, feature) end |
#agent_id_active?(feature, agent_id) ⇒ Boolean
72 73 74 |
# File 'lib/feature_creep/redis_data_store.rb', line 72 def agent_id_active?(feature, agent_id) @redis.sismember(agent_id_key(feature), agent_id) end |
#agent_id_within_active_percentage?(feature, agent_id) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/feature_creep/redis_data_store.rb', line 76 def agent_id_within_active_percentage?(feature, agent_id) percentage = active_percentage(feature) return false if percentage.nil? agent_id % 100 < percentage.to_i end |
#deactivate_agent_id(feature, agent_id) ⇒ Object
35 36 37 |
# File 'lib/feature_creep/redis_data_store.rb', line 35 def deactivate_agent_id(feature, agent_id) @redis.srem(agent_id_key(feature), agent_id) end |
#deactivate_all(feature) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/feature_creep/redis_data_store.rb', line 43 def deactivate_all(feature) @redis.del(scope_key(feature)) @redis.del(agent_id_key(feature)) @redis.del(percentage_key(feature)) deactivate_globally(feature) end |
#deactivate_globally(feature) ⇒ Object
Deactivate Methods
27 28 29 |
# File 'lib/feature_creep/redis_data_store.rb', line 27 def deactivate_globally(feature) @redis.srem(global_key, feature) end |
#deactivate_percentage(feature) ⇒ Object
39 40 41 |
# File 'lib/feature_creep/redis_data_store.rb', line 39 def deactivate_percentage(feature) @redis.del(percentage_key(feature)) end |
#deactivate_scope(feature, scope) ⇒ Object
31 32 33 |
# File 'lib/feature_creep/redis_data_store.rb', line 31 def deactivate_scope(feature, scope) @redis.srem(scope_key(feature), scope) end |
#features ⇒ Object
Utility Methods
83 84 85 |
# File 'lib/feature_creep/redis_data_store.rb', line 83 def features @redis.smembers(@key_prefix).map(&:to_sym) end |
#remove_feature(feature) ⇒ Object
91 92 93 |
# File 'lib/feature_creep/redis_data_store.rb', line 91 def remove_feature(feature) @redis.srem(@key_prefix, feature) end |