<commit_before>// Base Collection
// ---------------

// All exernal dependencies required in this scope.
var _         = require('lodash');
var inherits  = require('inherits');

// All components that need to be referenced in this scope.
var Events    = require('./events');
var Promise   = require('./promise');
var ModelBase = require('./model');

var array  = [];
var push   = array.push;
var slice  = array.slice;
var splice = array.splice;

function CollectionBase(models, options) {
  if (options) _.extend(this, _.pick(options, collectionProps));
  this._reset();
  if (!_.isFunction(this.model)) {
    throw new Error('A valid `model` constructor must be defined for all collections.');
  }
  if (models) this.reset(models, _.extend({silent: true}, options));
}
inherits(CollectionBase, Events);

// List of attributes attached directly from the constructor's options object.
var collectionProps = ['model', 'Model', 'comparator'];

// Copied over from Backbone.
var setOptions = {add: true, remove: true, merge: true};
var addOptions = {add: true, remove: false};

// The `tableName` on the associated Model, used in relation building.
CollectionBase.prototype.tableName = function() {
  return _.result(this.model.prototype, 'tableName');
};

// The `idAttribute` on the associated Model, used in relation building.
CollectionBase.prototype.idAttribute = function() {
  return this.model.prototype.idAttribute;
};

CollectionBase.prototype.toString = function() {
  return '[Object Collection]';
};

CollectionBase.prototype.serialize = function(options) {
  return this.map(function(model){ 
    return model.toJSON(options); <commit_msg>Fix regression, initialize not called in model constructor, #737<commit_after>// Base Collection
// ---------------

// All exernal dependencies required in this scope.
var _         = require('lodash');
var inherits  = require('inherits');

// All components that need to be referenced in this scope.
var Events    = require('./events');
var Promise   = require('./promise');
var ModelBase = require('./model');

var array  = [];
var push   = array.push;
var slice  = array.slice;
var splice = array.splice;

function CollectionBase(models, options) {
  if (options) _.extend(this, _.pick(options, collectionProps));
  this._reset();
  this.initialize.apply(this, arguments)
  if (!_.isFunction(this.model)) {
    throw new Error('A valid `model` constructor must be defined for all collections.');
  }
  if (models) this.reset(models, _.extend({silent: true}, options));
}
inherits(CollectionBase, Events);

// List of attributes attached directly from the constructor's options object.
var collectionProps = ['model', 'Model', 'comparator'];

// Copied over from Backbone.
var setOptions = {add: true, remove: true, merge: true};
var addOptions = {add: true, remove: false};

// The `tableName` on the associated Model, used in relation building.
CollectionBase.prototype.tableName = function() {
  return _.result(this.model.prototype, 'tableName');
};

// The `idAttribute` on the associated Model, used in relation building.
CollectionBase.prototype.idAttribute = function() {
  return this.model.prototype.idAttribute;
};

CollectionBase.prototype.toString = function() {
  return '[Object Collection]';
};

CollectionBase.prototype.serialize = function(options) {
  return this.map(function(model){ 
    return model.toJSON(options); 
{'fraction_non_alphanumeric': 0.14150943396226415, 'fraction_numerical': 0.000884433962264151, 'mean_word_length': 4.326530612244898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2721450', 'n_tokens_mistral': 936, 'n_tokens_neox': 926, 'n_words': 308}