PushAccumulator.js 865 B

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