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 Method Summary collapse

Constructor Details

#initialize(redis_key) ⇒ RedisRepository

Constructor

Parameters:

  • redis_key

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



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_featuresArray<Symbol>

Returns list of active features

Returns:

  • (Array<Symbol>)

    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

Parameters:

  • feature (Symbol)

    the feature to be added



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