<commit_before>
var Proteus = require("proteus"),
    IGNORE_METHODS = Proteus.enumerate("init", "attach"),
    Behavior
;
//---------------------------------------------------------------------------
// Privates // Short-cuts
//---------------------------------------------------------------------------
/**
 * @function makeProxy
 * @param {Object} behavior the behavior we are proxying
 * @param {Object} dice the dice object
 * @param {String} aspect the particular method/property we are proxying
 */
function makeProxy (dice, name) {
    var self, OP, ObjValueOf, ObjToString,
        selfSpec, selfGetter, selfSetter, selfValue, isFn, isObjProto,
        diceSpec, diceGetter, diceSetter, diceValue, proxy
    ;
    
    if (IGNORE_METHODS[name]) {
        return;
    }
    
    self        = this;
    OP          = Object.prototype;
    ObjValueOf  = OP.valueOf;
    ObjToString = OP.toString;
    selfSpec    = Proteus.getPropertyDescriptor(this, name);
    selfGetter  = selfSpec.get;
    selfSetter  = selfSpec.set;
    selfValue   = selfSpec.value;
    isFn        = typeof selfValue === "function";
    isObjProto  = selfValue === ObjValueOf || selfValue === ObjToString;
    
    if (selfGetter || selfSetter || (isFn && !isObjProto)) {
        diceSpec   = Proteus.getPropertyDescriptor(dice, name) || {};
        diceGetter = diceSpec.get;
        diceSetter = diceSpec.set;
        diceValue  = diceValue;
        
        proxy = function () {
            // console.log(aspect);
            var fn     = (arguments.length > 0 ? diceSetter : diceGetter) || diceValue,
                result = fn && fn.apply(dice, arguments),
                args   = [dice, result],
                ret    = self[name].apply(self, args)
            ;

            return ret === undefined ? result : ret;
        };

        if (diceGetter || diceSetter) {
            diceSpec.get = diceSpec.set = proxy;
        }
        else {
            diceSpec.value = proxy;
        }

        // console.log(aspect, spec);
        Object.defineProperty(dice, name, diceSpec);
    }
}
//---------------------------------------------------------------------------
// Exports
//---------------------------------------------------------------------------
module.exports = Behavior = Proteus.Class.derive({
    
    self: Object.defineProperties({
        
        initialize: function (instance, args) {
            // if behavior is undefined, the normal instantiation of behavior takes place
            return this.find(args[0]);
        },
        
        get: function (name) {
            var behavior = this.__behaviors__[name] || this.find(name);
            
            if (!behavior) {
                throw "Unknown behavior '" + name + "'";
            }
            
            return behavior;
        },
        
        find: function (name) {
            var behaviors = this.__behaviors__,
                behavior
            ;
            
            Object.keys(behaviors).some(function (key) {
                var obj = behaviors[key],
                    abbrev = obj.abbreviation
                ;
                
                if (key === name || abbrev === name) {
                    behavior = obj;
                    return true;
                }
            });
            
            return behavior;
        }
        
    }, {
        __behaviors__: { value: {} }
    }),
    
    init: function (name, props) {
        Proteus.merge(this, props);
        Behavior.__behaviors__[name] = this;
    },
    <commit_msg>Make sure to set the behavior's name.<commit_after>
var Proteus = require("proteus"),
    IGNORE_METHODS = Proteus.enumerate("init", "attach"),
    Behavior
;
//---------------------------------------------------------------------------
// Privates // Short-cuts
//---------------------------------------------------------------------------
/**
 * @function makeProxy
 * @param {Object} behavior the behavior we are proxying
 * @param {Object} dice the dice object
 * @param {String} aspect the particular method/property we are proxying
 */
function makeProxy (dice, name) {
    var self, OP, ObjValueOf, ObjToString,
        selfSpec, selfGetter, selfSetter, selfValue, isFn, isObjProto,
        diceSpec, diceGetter, diceSetter, diceValue, proxy
    ;
    
    if (IGNORE_METHODS[name]) {
        return;
    }
    
    self        = this;
    OP          = Object.prototype;
    ObjValueOf  = OP.valueOf;
    ObjToString = OP.toString;
    selfSpec    = Proteus.getPropertyDescriptor(this, name);
    selfGetter  = selfSpec.get;
    selfSetter  = selfSpec.set;
    selfValue   = selfSpec.value;
    isFn        = typeof selfValue === "function";
    isObjProto  = selfValue === ObjValueOf || selfValue === ObjToString;
    
    if (selfGetter || selfSetter || (isFn && !isObjProto)) {
        diceSpec   = Proteus.getPropertyDescriptor(dice, name) || {};
        diceGetter = diceSpec.get;
        diceSetter = diceSpec.set;
        diceValue  = diceValue;
        
        proxy = function () {
            // console.log(aspect);
            var fn     = (arguments.length > 0 ? diceSetter : diceGetter) || diceValue,
                result = fn && fn.apply(dice, arguments),
                args   = [dice, result],
                ret    = self[name].apply(self, args)
            ;

            return ret === undefined ? result : ret;
        };

        if (diceGetter || diceSetter) {
            diceSpec.get = diceSpec.set = proxy;
        }
        else {
            diceSpec.value = proxy;
        }

        // console.log(aspect, spec);
        Object.defineProperty(dice, name, diceSpec);
    }
}
//---------------------------------------------------------------------------
// Exports
//---------------------------------------------------------------------------
module.exports = Behavior = Proteus.Class.derive({
    
    self: Object.defineProperties({
        
        initialize: function (instance, args) {
            // if behavior is undefined, the normal instantiation of behavior takes place
            return this.find(args[0]);
        },
        
        get: function (name) {
            var behavior = this.__behaviors__[name] || this.find(name);
            
            if (!behavior) {
                throw "Unknown behavior '" + name + "'";
            }
            
            return behavior;
        },
        
        find: function (name) {
            var behaviors = this.__behaviors__,
                behavior
            ;
            
            Object.keys(behaviors).some(function (key) {
                var obj = behaviors[key],
                    abbrev = obj.abbreviation
                ;
                
                if (key === name || abbrev === name) {
                    behavior = obj;
                    return true;
                }
            });
            
            return behavior;
        }
        
    }, {
        __behaviors__: { value: {} }
    }),
    
    init: function (name, props) {
        Proteus.merge(this, props);
        this.name = name;
        Behavior.__behaviors__[name] = this;
    },
    
{'fraction_non_alphanumeric': 0.18627724986025712, 'fraction_numerical': 0.0005589714924538849, 'mean_word_length': 1.2706218274111676, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6518052', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1819, 'n_words': 428}