<commit_before>'use strict';

let events = require('events');
let _ = require('lodash');
let digsUtil = require('./digs-util');
let slugify = require('./slugify');

class DigsEmitter extends events.EventEmitter {

  constructor() {
    super();

    let name = slugify(this.constructor.name);
    this.id = _.uniqueId(`${name}-`);

    return new Proxy(this, {
      get: function (target, name) {
        let prop = name in target && target[name];
        let schemata;
        if (prop && _.isFunction(prop) && (schemata = prop.schemata)) {
          return function() {
            digsUtil.assertParams(arguments, schemata);
            return prop.apply(this, arguments);
          };
        }
        return target[name];
      }
    });
  }

  toString() {
    return `<${this.constructor.name}#${this.id}>`;
  }

  static create(prototype) {
    return _.create(DigsEmitter.prototype, prototype);
  }
}

module.exports = DigsEmitter;
<commit_msg>ensure id is generated as well as proxy; refactor slightly<commit_after>'use strict';

let events = require('events');
let _ = require('lodash');
let slugify = require('./slugify');

class DigsEmitter extends events.EventEmitter {

  constructor() {
    super();

    createId(this);
    createValidatorProxies(this);
  }

  toString() {
    return `<${this.constructor.name}#${this.id}>`;
  }

  /**
   * Create a DigsEmitter instance from raw object
   * @param {Object} prototype Some object
   * @returns {DigsEmitter} DigsEmitter instance
   */
  static create(prototype) {
    let obj = _.create(DigsEmitter.prototype, prototype);
    createId(obj);
    createValidatorProxies(obj);
    return obj;
  }
}

function createId(ctx) {
  let name = slugify(ctx.constructor.name);
  ctx.id = ctx.id || _.uniqueId(`${name}-`);
  return ctx;
}

function createValidatorProxies(ctx) {
  let assertParams = require('./digs-util').assertParams;

  _.each(_.functions(ctx), function (funcName) {
    let schemata;
    let func = this[funcName];
    if (_.has(this, funcName) && _.isArray((schemata = func.schemata))) {
      this[funcName] = function validatorProxy() {
        assertParams(arguments, schemata);
        return func.apply(this, arguments);
      };
    }
  }, ctx);

  return ctx;
}

module.exports = DigsEmitter;

{'fraction_non_alphanumeric': 0.14780701754385964, 'fraction_numerical': 0.0, 'mean_word_length': 3.1776556776556775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '57580', 'n_tokens_mistral': 719, 'n_tokens_neox': 709, 'n_words': 160}