<commit_before>/**
 * Resource class for list style resources,
 * thus collection is IndexMixin based
 */
var when = require('when');
var util = require('util');
var Resource = require('./resource');

var ListResource = function(name, options, app) {
  Resource.call(this, name, options, app);
};
util.inherits(ListResource, Resource);

ListResource.prototype._addParameterHandler = function () {
  var self = this;
  this.app.param('id', function(req, res, next, id) {
    self.listModel = self._constructModel(req);
    self.listModel.set(req.model.idAttribute, id);
    // no need to load parent model
    req.model.promise = when.resolve();
    next();
  });
};

ListResource.prototype.create = function(req, res, next) {
  throw new Error('create is not implemented');
};

// override default update -> addToIndex instead of update
ListResource.prototype.update = function(req, res, next) {
  var data = this.listModel;
  var collection = this._constructCollection(req);
  collection
    .addToIndex(data)
    .done(function () {
      req.model = res.locals.resource = data;
      next();
    }, next);
};

// override default remove -> removeFromIndex instead of destroy
ListResource.prototype.remove = function(req, res, next) {
  var data = this.listModel;
  var collection = this._constructCollection(req);
  collection
    .removeFromIndex(data)
    .done(function () {
      req.model = res.locals.resource = data;
      next();
    }, next);
};

ListResource.prototype.save = function (req, res, next) {
  next();
};


module.exports = ListResource;
<commit_msg>ListResource passes actor to action<commit_after>/**
 * Resource class for list style resources,
 * thus collection is IndexMixin based
 */
var when = require('when');
var util = require('util');
var Resource = require('./resource');

var ListResource = function(name, options, app) {
  Resource.call(this, name, options, app);
};
util.inherits(ListResource, Resource);

ListResource.prototype._addParameterHandler = function () {
  var self = this;
  this.app.param('id', function(req, res, next, id) {
    self.listModel = self._constructModel(req);
    self.listModel.set(req.model.idAttribute, id);
    // no need to load parent model
    req.model.promise = when.resolve();
    next();
  });
};

ListResource.prototype.create = function(req, res, next) {
  throw new Error('create is not implemented');
};

// override default update -> addToIndex instead of update
ListResource.prototype.update = function(req, res, next) {
  var data = this.listModel;
  var collection = this._constructCollection(req);
  collection
    .addToIndex(data, {actor: req.actor})
    .done(function () {
      req.model = res.locals.resource = data;
      next();
    }, next);
};

// override default remove -> removeFromIndex instead of destroy
ListResource.prototype.remove = function(req, res, next) {
  var data = this.listModel;
  var collection = this._constructCollection(req);
  collection
    .removeFromIndex(data, {actor: req.actor})
    .done(function () {
      req.model = res.locals.resource = data;
      next();
    }, next);
};

ListResource.prototype.save = function (req, res, next) {
  next();
};


module.exports = ListResource;

{'fraction_non_alphanumeric': 0.13947696139476962, 'fraction_numerical': 0.0, 'mean_word_length': 3.8461538461538463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4127031', 'n_tokens_mistral': 944, 'n_tokens_neox': 941, 'n_words': 254}