Class: Feature::Repository::RedisRepository

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(redis_key, client = nil) ⇒ RedisRepository

Constructor

Parameters:

  • redis_key

    the key of the redis hash where all the toggles will be stored



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

Parameters:

  • value

    the value to set the attribute redis to.



13
14
15
# File 'lib/feature/repository/redis_repository.rb', line 13

def redis=(value)
  @redis = value
end

Instance Method Details

#active_featuresArray<Symbol>

Returns list of active features

Returns:

  • (Array<Symbol>)

    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

Parameters:

  • feature (Symbol)

    the feature to be added



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