Class: Featurer::RedisAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/featurer/adapters/redis.rb

Instance Attribute Summary

Attributes inherited from Adapter

#config

Instance Method Summary collapse

Methods inherited from Adapter

inherited, #initialize

Constructor Details

This class inherits a constructor from Featurer::Adapter

Instance Method Details

#add(feature, value) ⇒ Object



12
13
14
# File 'lib/featurer/adapters/redis.rb', line 12

def add(feature, value)
  save_set(feature, value)
end

#delete(feature) ⇒ Object



16
17
18
# File 'lib/featurer/adapters/redis.rb', line 16

def delete(feature)
  delete_key(feature)
end

#enabled_features(value = true) ⇒ Object



27
28
29
30
31
32
# File 'lib/featurer/adapters/redis.rb', line 27

def enabled_features(value = true)
  all_features.select { |feature| on?(feature, value) }
rescue => e
  @config[:logger].warn e
  []
end

#feature_listObject



45
46
47
48
49
50
51
52
# File 'lib/featurer/adapters/redis.rb', line 45

def feature_list
  full_feature_names.map do |full_feature_name|
    {
      name: short_feature_name(full_feature_name),
      matching_values: @redis.smembers(full_feature_name)
    }
  end
end

#off(feature, value) ⇒ Object



34
35
36
# File 'lib/featurer/adapters/redis.rb', line 34

def off(feature, value)
  remove_from_set(feature, value)
end

#on?(feature, value = true) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/featurer/adapters/redis.rb', line 20

def on?(feature, value = true)
  fetch_from_set(feature, value)
rescue => e
  @config[:logger].warn e
  false
end

#prepareObject



6
7
8
9
10
# File 'lib/featurer/adapters/redis.rb', line 6

def prepare
  @redis = @config[:client] || ::Redis.new(host: @config[:host],
                                           port: @config[:port],
                                           db: @config[:db])
end

#register(feature, value = true) ⇒ Object



38
39
40
41
42
43
# File 'lib/featurer/adapters/redis.rb', line 38

def register(feature, value = true)
  return if feature.nil? || feature.empty?

  delete(feature)
  save_set(feature, value)
end