<commit_before>"use strict";
var _ = require('lodash'),
    util = require('./class_util');

function define(namespace, api) {

    var config, klass, parent,
        ignoredKeys = { constructor: true, prototype: true, $config: true, callParent: true };

    if (!api) {
        api = namespace;
        namespace = null;
    }

    //get config
    config = api.$config || {};

    //get api
    api = _.isFunction(api) ? api() : api;

    namespace = namespace || config.namespace || null;

    //set name
    config.name = config.name || (namespace && namespace.replace(/\./g, '_')) || "";

    //get parent
    parent = config.extends || function () {
    };

    //create constructor if not given
    if (_.has(api, 'constructor')) {

        //add call parent to constructor
        klass = (function (supProto) {

            if (config.name) {
                return new Function(
                    'supProto',
                    'api',
                        'return function ' + config.name + '() {' +
                        'this.callParent = supProto["constructor"];' +
                        'return api.constructor.apply(this, arguments);' +
                        '}'
                )(supProto, api)
            } else {
                return function () {
                    this.callParent = supProto["constructor"];
                    return api.constructor.apply(this, arguments);
                }
            }


        })(parent.prototype);
    }
    else if (config.extends) {
        //set constructor to be parent constructor
        klass = (function (parent) {

            if (config.name) {
                return new Function(
                    'parent',
                        'return function ' + config.name + ' () {parent.apply(this, arguments); }'
                )(parent)
            } else {

                return function () {
                    parent.apply(this, arguments);
                };
            }

        })(parent);

    } else { //constructor to empty function

        klass = config.name ? new Function('return function ' + config.name + ' () {}')() : function () {
        }
    }

    //create class prototype
    klass.prototype = Object.create(parent.prototype, {
        constructor: {
            value: klass,
            enumerable: false,
            writable: true,
            configurable: true
        }
    });

    //copy prototype
    _.forEach(api, function (func, name) {

        if (!ignoredKeys[name]) {

            if (!_.isFunction(func)) {
                klass.prototype[name] = func;
            } else {
                klass.prototype[name] = (function (name, func, supProto) {
                    return function () {

                        this.callParent = supProto[name];

                        try {
                            return func.apply(this, arguments);
                        } finally {
                            this.callParent = null;
                        }
                    }

                })(name, func, parent.prototype);
            }
        }
    });


    //add statics
    _.forEach(config.statics, function (func, name) {
        klass[name] = func;
        klass.prototype[name] = func;
    });

    //add mixin
    if (config.mixins) {
        _.forEach(_.isArray(config.mixins) ? config.mixins : [config.mixins], function (mixin) {

            _.forEach(mixin.prototype, function (mixinFunc, mixinName) {
                klass.prototype[mixinName] = mixinFunc;
            });
        });
    }

    //run on plugins
    _.forEach(plugins, function (func) {
        func(config, klass, parent);
    });

    //add define method for easy inheritance
    klass.define = (function (klass, define) {
        return function (namespace, api) {

            if (!api) {
                api = namespace;
                namespace = null;
            }

            api.$config = api.$config || {};

            api.$config.extends = klass;

            return define(namespace, api)
        }
    })(klass, define);

    if (namespace) {
        util.namespace(namespace, GLOBAL, klass);
    }

    _.forEach(config.members, function (property) {
        Object.defineProperty(klass.prototype, property, {
            get: util.memberGetterSetter('get' + util.capitaliseFirstLetter(property),klass.prototype),
            set: util.memberGetterSetter('set' + util.capitaliseFirstLetter(property),klass.prototype)
        });
    });


    return klass;
}

var plugins = [];

module.exports.define = define;

module.exports.addPlugin = function (func) {
    plugins.push(func)
};<commit_msg>Added support for object notation in members declarations<commit_after>"use strict";
var _ = require('lodash'),
    util = require('./class_util');

function define(namespace, api) {

    var config, klass, parent,
        ignoredKeys = { constructor: true, prototype: true, $config: true, callParent: true };

    if (!api) {
        api = namespace;
        namespace = null;
    }

    //get config
    config = api.$config || {};

    //get api
    api = _.isFunction(api) ? api() : api;

    namespace = namespace || config.namespace || null;

    //set name
    config.name = config.name || (namespace && namespace.replace(/\./g, '_')) || "";

    //get parent
    parent = config.extends || function () {
    };

    //create constructor if not given
    if (_.has(api, 'constructor')) {

        //add call parent to constructor
        klass = (function (supProto) {

            if (config.name) {
                return new Function(
                    'supProto',
                    'api',
                        'return function ' + config.name + '() {' +
                        'this.callParent = supProto["constructor"];' +
                        'return api.constructor.apply(this, arguments);' +
                        '}'
                )(supProto, api)
            } else {
                return function () {
                    this.callParent = supProto["constructor"];
                    return api.constructor.apply(this, arguments);
                }
            }


        })(parent.prototype);
    }
    else if (config.extends) {
        //set constructor to be parent constructor
        klass = (function (parent) {

            if (config.name) {
                return new Function(
                    'parent',
                        'return function ' + config.name + ' () {parent.apply(this, arguments); }'
                )(parent)
            } else {

                return function () {
                    parent.apply(this, arguments);
                };
            }

        })(parent);

    } else { //constructor to empty function

        klass = config.name ? new Function('return function ' + config.name + ' () {}')() : function () {
        }
    }

    //create class prototype
    klass.prototype = Object.create(parent.prototype, {
        constructor: {
            value: klass,
            enumerable: false,
            writable: true,
            configurable: true
        }
    });

    //copy prototype
    _.forEach(api, function (func, name) {

        if (!ignoredKeys[name]) {

            if (!_.isFunction(func)) {
                klass.prototype[name] = func;
            } else {
                klass.prototype[name] = (function (name, func, supProto) {
                    return function () {

                        this.callParent = supProto[name];

                        try {
                            return func.apply(this, arguments);
                        } finally {
                            this.callParent = null;
                        }
                    }

                })(name, func, parent.prototype);
            }
        }
    });


    //add statics
    _.forEach(config.statics, function (func, name) {
        klass[name] = func;
        klass.prototype[name] = func;
    });

    //add mixin
    if (config.mixins) {
        _.forEach(_.isArray(config.mixins) ? config.mixins : [config.mixins], function (mixin) {

            _.forEach(mixin.prototype, function (mixinFunc, mixinName) {
                klass.prototype[mixinName] = mixinFunc;
            });
        });
    }

    //run on plugins
    _.forEach(plugins, function (func) {
        func(config, klass, parent);
    });

    //add define method for easy inheritance
    klass.define = (function (klass, define) {
        return function (namespace, api) {

            if (!api) {
                api = namespace;
                namespace = null;
            }

            api.$config = api.$config || {};

            api.$config.extends = klass;

            return define(namespace, api)
        }
    })(klass, define);

    if (namespace) {
        util.namespace(namespace, GLOBAL, klass);
    }

    if(Array.isArray(config.members)) {
        _.forEach(config.members, function (property) {
            
            var getter = util.memberGetterSetter('get' + util.capitaliseFirstLetter(property), klass.prototype);
            var setter = util.memberGetterSetter('set' + util.capitaliseFirstLetter(property), klass.prototype);
            
            Object.defineProperty(klass.prototype, property, { get: getter, set: setter });
        });
    }
    else if (typeof config.members == 'object') {
        for (var key in config.members) {
            var property = key;
            var options = config.members[key]; // preperation for air conditioner

            if (options.toLowerCase() != 'auto') {
                throw new Error("only 'auto' property option is supported for now");
            }

            var getter = util.memberGetterSetter('get' + util.capitaliseFirstLetter(property), klass.prototype);
            var setter = util.memberGetterSetter('set' + util.capitaliseFirstLetter(property), klass.prototype);

            Object.defineProperty(klass.prototype, property, { get: getter, set: setter });
        }
    }

    return klass;
}

var plugins = [];

module.exports.define = define;

module.exports.addPlugin = function (func) {
    plugins.push(func)
};
{'fraction_non_alphanumeric': 0.12492593324116137, 'fraction_numerical': 0.0, 'mean_word_length': 1.5361883295767593, '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': '705939', 'n_tokens_mistral': 2694, 'n_tokens_neox': 2577, 'n_words': 609}