<commit_before>//   (c) 2013 <NAME>
//   MIT Licensed
//   For all details and documentation:
//   https://github.com/HenrikJoreteg/human-model
(function () {
  'use strict';

  // Initial setup
  // -------------

  // Establish the root object, `window` in the browser, or `global` on the server.
  var root = this;
  var toString = Object.prototype.toString;
  var slice = Array.prototype.slice;

  // Require Underscore, if we're on the server, and it's not already present.
  var _ = root._;
  var define;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore');

  // Require Backbone, if we're on the server, and it's not already present.
  var Backbone = root.Backbone;
  if (!Backbone && (typeof require !== 'undefined')) Backbone = require('backbone');

  // Backbone Collection compatibility fix:
  // In backbone, when you add an already instantiated model to a collection
  // the collection checks to see if what you're adding is already a model
  // the problem is, it does this witn an instanceof check. We're wanting to
  // use completely different models so the instanceof will fail even if they
  // are "real" models. So we work around this by overwriting this method from
  // backbone 1.0.0. The only difference is it compares against our HumanModel
  // instead of backbone's.
  Backbone.Collection.prototype._prepareModel = function (attrs, options) {
    if (attrs._definition) {
      if (!attrs.collection) attrs.collection = this;
      return attrs;
    }
    options || (options = {});
    options.collection = this;
    var model = new this.model(attrs, options);
    if (!model._validate(attrs, options)) {
      this.trigger('invalid', this, attrs, options);
      return false;
    }
    return model;
  };


  var createDerivedProperty = function (modelProto, name, definition) {
    var def = modelProto._derived[name] = {
      fn: _.isFunction(definition) ? definition : definition.fn,
      cache: (definition.cache !== false),
      depList: definition.deps || []
    };

    // add to our shared dependency list
    _.each(def.depList, function (dep) {
      modelProto._deps[dep] = _(modelProto._deps[dep] || []).union([name]);
    });

    // defined a top-level getter for derived names
    Object.defineProperty(modelProto, name, {
      get: function () {
        // is this a derived property we should cache?
        if (this._derived[name].cache) {
          // read through cache
          return this._cache[name] || (this._cache[name] = this._derived[name].fn.apply(this));
        } else {
          return this._derived[name].fn.apply(this);
        }
      },
      set: function (name) {
        var deps = this._derived[name].deps;
        var msg = '"' + name + '" is a derived property, you can\'t set it directly.';
        if (deps && deps.length) {
          throw new TypeError(msg + ' It is dependent on "' + deps.join('" and "') + '".');
        } else {
          throw new TypeError(msg);
        }<commit_msg>Fix setter for a derived property raising the wrong exception<commit_after>//   (c) 2013 <NAME>
//   MIT Licensed
//   For all details and documentation:
//   https://github.com/HenrikJoreteg/human-model
(function () {
  'use strict';

  // Initial setup
  // -------------

  // Establish the root object, `window` in the browser, or `global` on the server.
  var root = this;
  var toString = Object.prototype.toString;
  var slice = Array.prototype.slice;

  // Require Underscore, if we're on the server, and it's not already present.
  var _ = root._;
  var define;
  if (!_ && (typeof require !== 'undefined')) _ = require('underscore');

  // Require Backbone, if we're on the server, and it's not already present.
  var Backbone = root.Backbone;
  if (!Backbone && (typeof require !== 'undefined')) Backbone = require('backbone');

  // Backbone Collection compatibility fix:
  // In backbone, when you add an already instantiated model to a collection
  // the collection checks to see if what you're adding is already a model
  // the problem is, it does this witn an instanceof check. We're wanting to
  // use completely different models so the instanceof will fail even if they
  // are "real" models. So we work around this by overwriting this method from
  // backbone 1.0.0. The only difference is it compares against our HumanModel
  // instead of backbone's.
  Backbone.Collection.prototype._prepareModel = function (attrs, options) {
    if (attrs._definition) {
      if (!attrs.collection) attrs.collection = this;
      return attrs;
    }
    options || (options = {});
    options.collection = this;
    var model = new this.model(attrs, options);
    if (!model._validate(attrs, options)) {
      this.trigger('invalid', this, attrs, options);
      return false;
    }
    return model;
  };


  var createDerivedProperty = function (modelProto, name, definition) {
    var def = modelProto._derived[name] = {
      fn: _.isFunction(definition) ? definition : definition.fn,
      cache: (definition.cache !== false),
      depList: definition.deps || []
    };

    // add to our shared dependency list
    _.each(def.depList, function (dep) {
      modelProto._deps[dep] = _(modelProto._deps[dep] || []).union([name]);
    });

    // defined a top-level getter for derived names
    Object.defineProperty(modelProto, name, {
      get: function () {
        // is this a derived property we should cache?
        if (this._derived[name].cache) {
          // read through cache
          return this._cache[name] || (this._cache[name] = this._derived[name].fn.apply(this));
        } else {
          return this._derived[name].fn.apply(this);
        }
      },
      set: function (value) {
        var deps = this._derived[name].deps;
        var msg = '"' + name + '" is a derived property, you can\'t set it directly.';
        if (deps && deps.length) {
          throw new TypeError(msg + ' It is dependent on "' + deps.join('" and "') + '".');
        } else {
          throw new TypeError(msg);
        }
{'fraction_non_alphanumeric': 0.1298658273977141, 'fraction_numerical': 0.0023190326321020373, 'mean_word_length': 2.6907090464547676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3546961', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1691, 'n_words': 589}