class Flipper::Adapters::Moneta
Constants
- FEATURES_KEY
Attributes
Public: The name of the adapter.
Public Class Methods
Public
# File lib/flipper/adapters/moneta.rb, line 14 def initialize(moneta) @moneta = moneta @name = :moneta end
Public Instance Methods
Public: Adds a feature to the set of known features.
# File lib/flipper/adapters/moneta.rb, line 25 def add(feature) moneta[FEATURES_KEY] = features << feature.key.to_s true end
Public: Clears all the gate values for a feature.
# File lib/flipper/adapters/moneta.rb, line 39 def clear(feature) moneta[key(feature.key)] = default_config true end
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.
# 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 end true end
Public: Enables a gate for a given thing.
feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being enabled for the gate.
Returns true.
# File lib/flipper/adapters/moneta.rb, line 58 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 end true end
Public: The set of known features
# File lib/flipper/adapters/moneta.rb, line 20 def features moneta[FEATURES_KEY] || Set.new end
Public: Gets the values for all gates for a given feature.
Returns a Hash of Flipper::Gate#key => value.
# File lib/flipper/adapters/moneta.rb, line 47 def get(feature) default_config.merge(moneta[key(feature.key)].to_h) end
Public: Removes a feature from the set of known features and clears all the values for the feature.
# File lib/flipper/adapters/moneta.rb, line 32 def remove(feature) moneta[FEATURES_KEY] = features.delete(feature.key.to_s) moneta.delete(key(feature.key)) true end
Private Instance Methods
# File lib/flipper/adapters/moneta.rb, line 102 def key(feature_key) "#{FEATURES_KEY}/#{feature_key}" end