<commit_before>/**
 * Created by Awesome on 1/30/2016.
 */

    // use strict
'use strict';

// require dependencies
var co        = require ('co');
var mongorito = require ('mongorito');

// require local dependencies
var models = require (global.appRoot + '/app/cache/models');

/**
 * build model
 */
class model extends mongorito.Model {
    /**
     * construct model entity
     *
     * @param {*} a
     * @param {*} b
     */
    constructor (a, b) {
        // run super
        super (a, b);

        // bind set/get methods
        this.getAttribute  = this.getAttribute.bind (this);
        this.setAttributes = this.setAttributes.bind (this);

        // bind model methods
        this.model   = this.model.bind (this);
        this.isModel = this.isModel.bind (this);

        // set attributes before save
        this.before ('save', 'setAttributes');
    }

    /**
     * gets model
     *
     * @param key
     * @returns {Promise}
     */
    model (key) {
        return this.getAttribute (key);
    }

    /**
     * gets attribute
     *
     * @param key
     * @returns {Promise}
     */
    getAttribute (key) {
        // set variables
        var that = this;
        // return promise
        return new Promise ((resolve, reject) => {
            // run coroutine
            co (function * () {
                // set let attribute
                let attr  = that.attributes[key];
                var load  = false;
                var Model = false;

                // check if is object
                if (attr === Object (attr) && attr.model && attr.id) {
                    // load model
                    Model = yield that._require (attr.model);

                    // yield model
                    load = yield Model.findById (attr.id);

                    // set model
                    that.set (key, load);
                } else if (Array.isArray (attr)) {
                    // set array variable
                    var arr = [];
                    // loop object array
                    for (var i = 0; i < attr.length; i++) {
                        // check if is object
                        if (attr[i] === Object (attr[i]) && attr[i].model && attr[i].id) {
                            // load model
                            Model = yield that._require (attr[i].model);

                            // yield model
                            load = yield Model.findById (attr[i].id);

                            // set model
                            arr.push (load);
                        } else {
                            arr.push (attr[i]);
                        }
                    }

                    // set array
                    that.set (key, arr);
                }

                // return
                resolve (that.get (key));
            });
        });
    }

    /**
     * sets attributes
     *
     * @param next
     */
    setAttributes (next) {
        // run that
        var that = this;

        // run coroutine
        co (function * () {
            // loop attributes
            for (var key in that.attributes) {
                // set let attribute
                let attr = that.attributes[key];

                // check if entity
                if (that.isModel (attr)) {
                    // set array for save
                    that.attributes[key] = {
                        'id'    : attr.get ('_id').toString (),
                        'model' : attr.constructor.name
                    };
                } else if (Array.isArray (attr)) {
                    // set arr variable
                    var arr = [];
                    // loop object array
                    for (var i = 0; i < attr.length; i++) {
                        // check if is object
                        if (that.isModel (attr[i])) {
                            arr.push ({
                                'id'    : attr[i].get ('_id').toString (),
                                'model' : attr[i].constructor.name
                            });
                        } else {
                            arr.push (attr[i]);
                        }
                    }

                    // set array
                    that.attributes[key] = arr;
                }
            }

            // run next
            yield next;
        });
    }

    /**
     * check if model
     *
     * @param obj
     * @returns {boolean}
     * @private
     */
    isModel (obj) {
        // check if model
        if (obj.attributes && obj.isModel && obj._modelLocation) {
            return true;
        }
    }

    /**
     * require model file
     *
     * @param  {String} Model
     *
     * @return {*}
     */
    _require (Model) {
        // check model name
        Model = Model.split ('/')[Model.split ('/').length - 1].split ('.')[0].toLowerCase ();

        // return promise
        return new Promise ((resolve, reject) => {
            // check if model exists
            if (!models[Model]) {<commit_msg>amend issues with model location dependency for isModel in model class<commit_after>/**
 * Created by Awesome on 1/30/2016.
 */

    // use strict
'use strict';

// require dependencies
var co        = require ('co');
var mongorito = require ('mongorito');

// require local dependencies
var models = require (global.appRoot + '/app/cache/models');

/**
 * build model
 */
class model extends mongorito.Model {
    /**
     * construct model entity
     *
     * @param {*} a
     * @param {*} b
     */
    constructor (a, b) {
        // run super
        super (a, b);

        // bind set/get methods
        this.getAttribute  = this.getAttribute.bind (this);
        this.setAttributes = this.setAttributes.bind (this);

        // bind model methods
        this.model   = this.model.bind (this);
        this.isModel = this.isModel.bind (this);

        // set attributes before save
        this.before ('save', 'setAttributes');
    }

    /**
     * gets model
     *
     * @param key
     * @returns {Promise}
     */
    model (key) {
        return this.getAttribute (key);
    }

    /**
     * gets attribute
     *
     * @param key
     * @returns {Promise}
     */
    getAttribute (key) {
        // set variables
        var that = this;
        // return promise
        return new Promise ((resolve, reject) => {
            // run coroutine
            co (function * () {
                // set let attribute
                let attr  = that.attributes[key];
                var load  = false;
                var Model = false;

                // check if is object
                if (attr === Object (attr) && attr.model && attr.id) {
                    // load model
                    Model = yield that._require (attr.model);

                    // yield model
                    load = yield Model.findById (attr.id);

                    // set model
                    that.set (key, load);
                } else if (Array.isArray (attr)) {
                    // set array variable
                    var arr = [];
                    // loop object array
                    for (var i = 0; i < attr.length; i++) {
                        // check if is object
                        if (attr[i] === Object (attr[i]) && attr[i].model && attr[i].id) {
                            // load model
                            Model = yield that._require (attr[i].model);

                            // yield model
                            load = yield Model.findById (attr[i].id);

                            // set model
                            arr.push (load);
                        } else {
                            arr.push (attr[i]);
                        }
                    }

                    // set array
                    that.set (key, arr);
                }

                // return
                resolve (that.get (key));
            });
        });
    }

    /**
     * sets attributes
     *
     * @param next
     */
    setAttributes (next) {
        // run that
        var that = this;

        // run coroutine
        co (function * () {
            // loop attributes
            for (var key in that.attributes) {
                // set let attribute
                let attr = that.attributes[key];

                // check if entity
                if (that.isModel (attr)) {
                    // set array for save
                    that.attributes[key] = {
                        'id'    : attr.get ('_id').toString (),
                        'model' : attr.constructor.name
                    };
                } else if (Array.isArray (attr)) {
                    // set arr variable
                    var arr = [];
                    // loop object array
                    for (var i = 0; i < attr.length; i++) {
                        // check if is object
                        if (that.isModel (attr[i])) {
                            arr.push ({
                                'id'    : attr[i].get ('_id').toString (),
                                'model' : attr[i].constructor.name
                            });
                        } else {
                            arr.push (attr[i]);
                        }
                    }

                    // set array
                    that.attributes[key] = arr;
                }
            }

            // run next
            yield next;
        });
    }

    /**
     * check if model
     *
     * @param obj
     * @returns {boolean}
     * @private
     */
    isModel (obj) {
        // check if model
        if (obj.attributes && obj.isModel) {
            return true;
        }
    }

    /**
     * require model file
     *
     * @param  {String} Model
     *
     * @return {*}
     */
    _require (Model) {
        // check model name
        Model = Model.split ('/')[Model.split ('/').length - 1].split ('.')[0].toLowerCase ();

        // return promise
        return new Promise ((resolve, reject) => {
            // check if model exists
            if (!models[Model]) {
{'fraction_non_alphanumeric': 0.1175716960678033, 'fraction_numerical': 0.002168128510889918, 'mean_word_length': 0.935163996948894, 'pattern_counts': {'":': 0, '<': 7, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4407838', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2455, 'n_words': 693}