<commit_before>/**
 * Promised models
 */

var EventEmitter = require('eventemitter3'),
    Vow = require('vow'),
    uniq = require('./uniq'),
    Inheritable = require('./inheritable'),
    fulfill = require('./fulfill'),
    IdAttribute = require('./types/id'),

    /**
     * bind events on attributes or model
     * @param  {EventEmitter} eventEmitter
     * @param  {string}   method of EventEmitter
     * @param  {string}   [attribute] space separated list
     * @param  {string}   event space separated list
     * @param  {Function} cb
     * @param  {*}   [ctx]
     */
    callEventEmitter = function (eventEmitter, method, attribute, event, cb, ctx) {
        if (typeof event !== 'string') {
            ctx = cb;
            cb = event;
            event = attribute;
            attribute = undefined;
        }
        ctx = ctx || this;
        if (attribute) {
            attribute.split(/\s+/).forEach(function (attribute) {
                event.split(/\s+/).forEach(function (event) {
                    eventEmitter[method](event + ':' + attribute, cb, ctx);
                });
            });
        } else {
            event.split(/\s+/).forEach(function (event) {
                eventEmitter[method](event, cb, ctx);
            });
        }
    },


    /**
     * @class
     * @prop {object} [data] initial data
     */
    Model = Inheritable.inherit({

        /**
         * @deprecated use getId method
         */
        id: null,

        /**
         * @param {*} [id]
         * @param {Object} [data]
         */
        __constructor: function (id, data) {
            var model = this,
                Storage = this.storage || Model.Storage,
                hasIdAttribute,
                modelAttributes;

            this.CHANGE_BRANCH = uniq();
            this.CALCULATIONS_BRANCH = uniq();
            if (arguments.length === 1) {
                if (typeof id === 'object') {
                    data = id;
                    id = null;
                }
            }

            data = data || {};

            this._eventEmitter = new EventEmitter();
            this._ready = true;
            this._readyPromise = fulfill();
            this.storage = new Storage();

            modelAttributes = this.__self.attributes || {};
            hasIdAttribute = Object.keys(modelAttributes).some(function (name) {
                return modelAttributes[name].prototype.isId;
            });

            if (!hasIdAttribute) {
                modelAttributes.id = IdAttribute;<commit_msg>Get attributes from instanse<commit_after>/**
 * Promised models
 */

var EventEmitter = require('eventemitter3'),
    Vow = require('vow'),
    uniq = require('./uniq'),
    Inheritable = require('./inheritable'),
    fulfill = require('./fulfill'),
    IdAttribute = require('./types/id'),

    /**
     * bind events on attributes or model
     * @param  {EventEmitter} eventEmitter
     * @param  {string}   method of EventEmitter
     * @param  {string}   [attribute] space separated list
     * @param  {string}   event space separated list
     * @param  {Function} cb
     * @param  {*}   [ctx]
     */
    callEventEmitter = function (eventEmitter, method, attribute, event, cb, ctx) {
        if (typeof event !== 'string') {
            ctx = cb;
            cb = event;
            event = attribute;
            attribute = undefined;
        }
        ctx = ctx || this;
        if (attribute) {
            attribute.split(/\s+/).forEach(function (attribute) {
                event.split(/\s+/).forEach(function (event) {
                    eventEmitter[method](event + ':' + attribute, cb, ctx);
                });
            });
        } else {
            event.split(/\s+/).forEach(function (event) {
                eventEmitter[method](event, cb, ctx);
            });
        }
    },


    /**
     * @class
     * @prop {object} [data] initial data
     */
    Model = Inheritable.inherit({

        /**
         * @deprecated use getId method
         */
        id: null,

        /**
         * @param {*} [id]
         * @param {Object} [data]
         */
        __constructor: function (id, data) {
            var model = this,
                Storage = this.storage || Model.Storage,
                hasIdAttribute,
                modelAttributes;

            this.CHANGE_BRANCH = uniq();
            this.CALCULATIONS_BRANCH = uniq();
            if (arguments.length === 1) {
                if (typeof id === 'object') {
                    data = id;
                    id = null;
                }
            }

            data = data || {};

            this._eventEmitter = new EventEmitter();
            this._ready = true;
            this._readyPromise = fulfill();
            this.storage = new Storage();

            modelAttributes = this.attributes || {};
            hasIdAttribute = Object.keys(modelAttributes).some(function (name) {
                return modelAttributes[name].prototype.isId;
            });

            if (!hasIdAttribute) {
                modelAttributes.id = IdAttribute;
{'fraction_non_alphanumeric': 0.13175411119812058, 'fraction_numerical': 0.0007830853563038371, 'mean_word_length': 1.4982885085574573, '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': '1589447', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1333, 'n_words': 312}