lib/flipper/adapters/mongo.rb in flipper-mongo-0.5.0 vs lib/flipper/adapters/mongo.rb in flipper-mongo-0.6.0
- old
+ new
@@ -16,10 +16,33 @@
def initialize(collection)
@collection = collection
@name = :mongo
end
+ # Public: The set of known features.
+ def features
+ find(FeaturesKey).fetch('features') { Set.new }.to_set
+ end
+
+ # Public: Adds a feature to the set of known features.
+ def add(feature)
+ update FeaturesKey, '$addToSet' => {'features' => feature.name.to_s}
+ true
+ end
+
+ # Public: Removes a feature from the set of known features.
+ def remove(feature)
+ update FeaturesKey, '$pull' => {'features' => feature.name.to_s}
+ clear feature
+ true
+ end
+
+ # Public: Clears all the gate values for a feature.
+ def clear(feature)
+ delete feature.key
+ end
+
# Public: Gets the values for all gates for a given feature.
#
# Returns a Hash of Flipper::Gate#key => value.
def get(feature)
result = {}
@@ -71,11 +94,11 @@
#
# Returns true.
def disable(feature, gate, thing)
case gate.data_type
when :boolean
- remove feature.key
+ delete feature.key
when :integer
update feature.key, '$set' => {gate.key.to_s => thing.value.to_s}
when :set
update feature.key, '$pull' => {gate.key.to_s => thing.value.to_s}
else
@@ -83,21 +106,10 @@
end
true
end
- # Public: Adds a feature to the set of known features.
- def add(feature)
- update FeaturesKey, '$addToSet' => {'features' => feature.name.to_s}
- true
- end
-
- # Public: The set of known features.
- def features
- find(FeaturesKey).fetch('features') { Set.new }.to_set
- end
-
# Private
def unsupported_data_type(data_type)
raise "#{data_type} is not supported by this adapter"
end
@@ -111,10 +123,10 @@
options = {:upsert => true}
@collection.update criteria(key), updates, options
end
# Private
- def remove(key)
+ def delete(key)
@collection.remove criteria(key)
end
# Private
def criteria(key)