lib/rocket_job/plugins/document.rb in rocketjob-3.4.3 vs lib/rocket_job/plugins/document.rb in rocketjob-3.5.0

- old
+ new

@@ -32,19 +32,17 @@ private # Apply changes to this document returning the updated document from the database. # Allows other changes to be made on the server that will be loaded. def find_and_update(attrs) - if doc = collection.find(_id: id).find_one_and_update({'$set' => attrs}, return_document: :after) - # Clear out keys that are not returned during the reload from MongoDB - (fields.keys + embedded_relations.keys - doc.keys).each { |key| send("#{key}=", nil) } - @attributes = doc - apply_defaults - self - else - raise(Mongoid::Errors::DocumentNotFound.new(self.class, id)) - end - end + doc = collection.find(_id: id).find_one_and_update({'$set' => attrs}, return_document: :after) + raise(Mongoid::Errors::DocumentNotFound.new(self.class, id)) unless doc + # Clear out keys that are not returned during the reload from MongoDB + (fields.keys + embedded_relations.keys - doc.keys).each { |key| send("#{key}=", nil) } + @attributes = doc + apply_defaults + self + end end end end