lib/flipper/adapters/mongo.rb in flipper-mongo-0.10.2 vs lib/flipper/adapters/mongo.rb in flipper-mongo-0.11.0.beta1

- old
+ new

@@ -23,17 +23,17 @@ 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.key} + update FeaturesKey, '$addToSet' => { 'features' => feature.key } true end # Public: Removes a feature from the set of known features. def remove(feature) - update FeaturesKey, '$pull' => {'features' => feature.key} + update FeaturesKey, '$pull' => { 'features' => feature.key } clear feature true end # Public: Clears all the gate values for a feature. @@ -93,13 +93,13 @@ def disable(feature, gate, thing) case gate.data_type when :boolean delete feature.key when :integer - update feature.key, '$set' => {gate.key.to_s => thing.value.to_s} + 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} + update feature.key, '$pull' => { gate.key.to_s => thing.value.to_s } else unsupported_data_type gate.data_type end true @@ -110,43 +110,44 @@ raise "#{data_type} is not supported by this adapter" end # Private def find(key) - @collection.find({:_id => key.to_s}).limit(1).first || {} + @collection.find(_id: key.to_s).limit(1).first || {} end def find_many(keys) - docs = @collection.find({_id: {'$in' => keys}}).to_a + docs = @collection.find(_id: { '$in' => keys }).to_a result = Hash.new { |hash, key| hash[key] = {} } docs.each do |doc| - result[doc["_id"]] = doc + result[doc['_id']] = doc end result end # Private def update(key, updates) - options = {:upsert => true} - @collection.find({:_id => key.to_s}).update_one(updates, options) + options = { upsert: true } + @collection.find(_id: key.to_s).update_one(updates, options) end # Private def delete(key) - @collection.find({:_id => key.to_s}).delete_one + @collection.find(_id: key.to_s).delete_one end def result_for_feature(feature, doc) result = {} feature.gates.each do |gate| - result[gate.key] = case gate.data_type - when :boolean, :integer - doc[gate.key.to_s] - when :set - doc.fetch(gate.key.to_s) { Set.new }.to_set - else - unsupported_data_type gate.data_type - end + result[gate.key] = + case gate.data_type + when :boolean, :integer + doc[gate.key.to_s] + when :set + doc.fetch(gate.key.to_s) { Set.new }.to_set + else + unsupported_data_type gate.data_type + end end result end end end