Browse Source

REFS DEVOPS-238 Added v2.5 compatibility

David Aebersold 11 years ago
parent
commit
10ccefe7e7

+ 15 - 6
lib/pipeline/expressions/CoerceToBoolExpression.js

@@ -19,12 +19,6 @@ var Value = require("../Value"),
 	OrExpression = require("./OrExpression"),
 	NotExpression = require("./NotExpression");
 
-// PROTOTYPE MEMBERS
-proto.evaluate = function evaluate(doc){
-	var result = this.expression.evaluate(doc);
-	return Value.coerceToBool(result);
-};
-
 proto.optimize = function optimize() {
 	this.expression = this.expression.optimize();	// optimize the operand
 
@@ -43,6 +37,21 @@ proto.addDependencies = function addDependencies(deps, path) {
 	return this.expression.addDependencies(deps);
 };
 
+// PROTOTYPE MEMBERS
+proto.evaluateInternal = function evaluateInternal(doc){
+	var result = this.expression.evaluateInternal(doc);
+	return Value.coerceToBool(result);
+};
+
+proto.serialize = function serialize(explain) {
+	if ( explain ) {
+		return {$coerceToBool:[this.expression.toJSON()]};
+	}
+	else {
+		return {$and:[this.expression.toJSON()]};
+	}
+};
+
 proto.toJSON = function toJSON() {
 	// Serializing as an $and expression which will become a CoerceToBool
 	return {$and:[this.expression.toJSON()]};

+ 2 - 2
test/lib/pipeline/expressions/CoerceToBoolExpression.js

@@ -23,12 +23,12 @@ module.exports = {
 
 			"should return true if nested expression is coerced to true; {$const:5}": function testEvaluateTrue(){
 				var expr = new CoerceToBoolExpression(new ConstantExpression(5));
-				assert.equal(expr.evaluate({}), true);
+				assert.equal(expr.evaluateInternal({}), true);
 			},
 
 			"should return false if nested expression is coerced to false; {$const:0}": function testEvaluateFalse(){
 				var expr = new CoerceToBoolExpression(new ConstantExpression(0));
-				assert.equal(expr.evaluate({}), false);
+				assert.equal(expr.evaluateInternal({}), false);
 			}
 
 		},