Class: Flipper::Adapters::Moneta
- Inherits:
-
Object
- Object
- Flipper::Adapters::Moneta
- Includes:
- Flipper::Adapter
- Defined in:
- lib/flipper/adapters/moneta.rb
Constant Summary collapse
- FEATURES_KEY =
:flipper_features
Instance Method Summary collapse
-
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
-
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
-
#disable(feature, gate, thing) ⇒ Object
Public: Disables a gate for a given thing.
-
#enable(feature, gate, thing) ⇒ Object
Public: Enables a gate for a given thing.
-
#features ⇒ Object
Public: The set of known features.
-
#get(feature) ⇒ Object
Public: Gets the values for all gates for a given feature.
-
#initialize(moneta) ⇒ Moneta
constructor
Public.
-
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features and clears all the values for the feature.
Methods included from Flipper::Adapter
#default_config, #export, #get_all, #get_multi, #import, included, #name, #read_only?
Constructor Details
#initialize(moneta) ⇒ Moneta
Public
11 12 13 |
# File 'lib/flipper/adapters/moneta.rb', line 11 def initialize(moneta) @moneta = moneta end |
Instance Method Details
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
21 22 23 24 |
# File 'lib/flipper/adapters/moneta.rb', line 21 def add(feature) moneta[FEATURES_KEY] = features << feature.key.to_s true end |
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
35 36 37 38 |
# File 'lib/flipper/adapters/moneta.rb', line 35 def clear(feature) moneta[key(feature.key)] = default_config true end |
#disable(feature, gate, thing) ⇒ Object
Public: Disables a gate for a given thing.
feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being disabled for the gate.
Returns true.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/flipper/adapters/moneta.rb', line 84 def disable(feature, gate, thing) case gate.data_type when :boolean clear(feature) when :integer result = get(feature) result[gate.key] = thing.value.to_s moneta[key(feature.key)] = result when :set result = get(feature) result[gate.key] = result[gate.key].delete(thing.value.to_s) moneta[key(feature.key)] = result when :json result = get(feature) result[gate.key] = nil moneta[key(feature.key)] = result end true end |
#enable(feature, gate, thing) ⇒ Object
Public: Enables a gate for a given thing.
feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to enable. thing - The Flipper::Type being enabled for the gate.
Returns true.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/flipper/adapters/moneta.rb', line 54 def enable(feature, gate, thing) case gate.data_type when :boolean clear(feature) result = get(feature) result[gate.key] = thing.value.to_s moneta[key(feature.key)] = result when :integer result = get(feature) result[gate.key] = thing.value.to_s moneta[key(feature.key)] = result when :set result = get(feature) result[gate.key] << thing.value.to_s moneta[key(feature.key)] = result when :json result = get(feature) result[gate.key] = thing.value moneta[key(feature.key)] = result end true end |
#features ⇒ Object
Public: The set of known features
16 17 18 |
# File 'lib/flipper/adapters/moneta.rb', line 16 def features moneta[FEATURES_KEY] || Set.new end |
#get(feature) ⇒ Object
Public: Gets the values for all gates for a given feature.
Returns a Hash of Flipper::Gate#key => value.
43 44 45 |
# File 'lib/flipper/adapters/moneta.rb', line 43 def get(feature) default_config.merge(moneta[key(feature.key)].to_h) end |
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features and clears all the values for the feature.
28 29 30 31 32 |
# File 'lib/flipper/adapters/moneta.rb', line 28 def remove(feature) moneta[FEATURES_KEY] = features.delete(feature.key.to_s) moneta.delete(key(feature.key)) true end |