PushAccumulator.js 879 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var PushAccumulator = module.exports = (function(){
  3. // Constructor
  4. /**
  5. * Constructor for PushAccumulator. Pushes items onto an array.
  6. *
  7. * @class PushAccumulator
  8. * @namespace munge.pipeline.accumulators
  9. * @module munge
  10. * @constructor
  11. **/
  12. var klass = module.exports = function PushAccumulator(){
  13. this.values = [];
  14. base.call(this);
  15. }, Accumulator = require("./Accumulator"), base = Accumulator, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  16. proto.evaluate = function evaluate(doc){
  17. if(this.operands.length != 1) throw new Error("this should never happen");
  18. var v = this.operands[0].evaluate(doc);
  19. if(v)
  20. this.values.push(v);
  21. return null;
  22. };
  23. proto.getValue = function getValue(){
  24. return this.values;
  25. };
  26. proto.getOpName = function getOpName(){
  27. return "$push";
  28. };
  29. return klass;
  30. })();