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 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) ⇒ RedisRepository
constructor
Constructor.
Constructor Details
#initialize(redis_key) ⇒ RedisRepository
Constructor
17 18 19 |
# File 'lib/feature/repository/redis_repository.rb', line 17 def initialize(redis_key) @redis_key = redis_key end |
Instance Method Details
#active_features ⇒ Array<Symbol>
Returns list of active features
25 26 27 |
# File 'lib/feature/repository/redis_repository.rb', line 25 def active_features Redis.current.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
33 34 35 36 37 |
# File 'lib/feature/repository/redis_repository.rb', line 33 def add_active_feature(feature) check_feature_is_not_symbol(feature) check_feature_already_in_list(feature) Redis.current.hset(@redis_key, feature, true) end |