| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- "use strict";
- /**
- * Matcher2 is a simple wrapper around a JSONObj and the MatchExpression created from it.
- * @class Matcher2
- * @namespace mungedb-aggregate.pipeline.matcher2
- * @module mungedb-aggregate
- * @constructor
- */
- var Matcher2 = module.exports = function Matcher2(pattern, nested){
- this._pattern = pattern;
- this.parser = new MatchExpressionParser();
- var result = this.parser.parse(pattern);
- if (result.code != ErrorCodes.OK)
- return {code:16810, description:"bad query: " + result};
- this._expression = result.result;
- }, klass = Matcher2, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
- // DEPENDENCIES
- var errors = require("../../Errors.js"),
- ErrorCodes = errors.ErrorCodes,
- MatchExpressionParser = require("./MatchExpressionParser.js");
- //PROTOTYPE MEMBERS
- proto._expression = undefined;
- proto._pattern = undefined;
- /**
- *
- * matches checks the input doc against the internal element path to see if it is a match
- * @method matches
- * @param doc
- * @param details
- *
- */
- proto.matches = function matches(doc, details){
- if (!this._expression)
- return true;
- return this._expression.matchesJSON(doc, details);
- };
- /**
- *
- * Return the _pattern property
- * @method getQuery
- *
- */
- proto.getQuery = function getQuery(){
- return this._pattern;
- };
- /**
- *
- * Convert _pattern into a string
- * @method toString
- *
- */
- proto.toString = function toString(){
- return this._pattern.toString();
- };
|