From 671539a61419de92c7320db6c0ff7caad4f76c56 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Wed, 19 Jun 2013 17:48:23 +0200 Subject: [PATCH] Implemented modifier --- lib/model.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/model.js b/lib/model.js index 622977d..2f7f1e4 100644 --- a/lib/model.js +++ b/lib/model.js @@ -9,6 +9,7 @@ var dateToJSON = function () { return { $$date: this.getTime() }; } , util = require('util') , _ = require('underscore') , modifierFunctions = {} + , lastStepModifierFunctions = {} , comparisonFunctions = {} , logicalOperators = {} ; @@ -213,6 +214,22 @@ function compareThings (a, b) { // Updating documents // ============================================================== + +lastStepModifierFunctions.$set = function (obj, field, value) { + obj[field] = value; +}; + +function findLastModificationStep (modifier, obj, field, value) { + var fieldParts = typeof field === 'string' ? field.split('.') : field; + + if (fieldParts.length === 1) { + lastStepModifierFunctions[modifier](obj, field, value); + } else { + obj[fieldParts[0]] = obj[fieldParts[0]] || {}; + modifierFunctions[modifier](obj[fieldParts[0]], fieldParts.slice(1), value); + } +} + /** * Set field to value in a model * Create it if it doesn't exist