Class: Feature::Repository::RedisRepository
- Inherits:
-
Object
- Object
- Feature::Repository::RedisRepository
- Defined in:
- lib/feature/repository/redis_repository.rb
Overview
RedisRepository for active feature list
Example usage:
repository = RedisRepository.new("feature_toggles")
repository.add_active_feature(:feature_name)
‘feature_toggles’ can be whatever name you want to use for the Redis hash that will store all of your feature toggles.
Instance Attribute Summary collapse
-
#redis ⇒ Object
writeonly
Sets the attribute redis.
Instance Method Summary collapse
-
#active_features ⇒ Array<Symbol>
Returns list of active features.
-
#add_active_feature(feature) ⇒ Object
Add an active feature to repository.
-
#initialize(redis_key, client = nil) ⇒ RedisRepository
constructor
Constructor.
Constructor Details
#initialize(redis_key, client = nil) ⇒ RedisRepository
Constructor
19 20 21 22 |
# File 'lib/feature/repository/redis_repository.rb', line 19 def initialize(redis_key, client = nil) @redis_key = redis_key @redis = client unless client.nil? end |
Instance Attribute Details
#redis=(value) ⇒ Object
Sets the attribute redis
13 14 15 |
# File 'lib/feature/repository/redis_repository.rb', line 13 def redis=(value) @redis = value end |
Instance Method Details
#active_features ⇒ Array<Symbol>
Returns list of active features
28 29 30 |
# File 'lib/feature/repository/redis_repository.rb', line 28 def active_features redis.hgetall(@redis_key).select { |_k, v| v.to_s == 'true' }.map { |k, _v| k.to_sym } end |
#add_active_feature(feature) ⇒ Object
Add an active feature to repository
36 37 38 39 40 |
# File 'lib/feature/repository/redis_repository.rb', line 36 def add_active_feature(feature) check_feature_is_not_symbol(feature) check_feature_already_in_list(feature) redis.hset(@redis_key, feature, true) end |