<commit_before>"use strict";
!function () {
    var get = Ember.get, set = Ember.set, getConverter = Frzn.getConverter, relationships = Frzn.relationships;

    var setupRelationship = function(model, name, options) {
        //For relationships we create a wrapper object using Ember proxies
        if(typeof options.destination == 'string') {
            var dst = get(options.destination);
            if(!dst) {
                var s = options.destination.split('.');
                if(s.length) {
                    dst = Ember.Namespace.byName(s[0]).get(s.slice(1).join('.'));
                }
            }
            options.destination = dst;
        }
        Ember.assert("You must provide a valid model class for field " + name, options.destination != null && options.destination != undefined);
        var rel = relationships[options.relationshipType].create({
            type: options.relationshipType,
            options: options
        });
        var data = get(model, '_data');
        var rels = get(model, '_relationships');
        set(rels, name, rel);
        set(data, name, undefined);
    };

    var initValidators = function(model, name, options) {
        if(options && !$.isEmptyObject(options)) {
            var validators = get(model, '_validators');
            var a = []
            for(var k in options) {
                if(options.hasOwnProperty(k)) {
                    var v = Frzn.createValidator(k, options[k]);
                    if(v) {
                        a.push(v);
                    }
                }
            }
            validators[name] = a;
        }
    };

    /**
     * Initialize a model field. This function tries to understand what kind of attribute should be
     * instantiated, along with converters and relationships.
     *
     * @param model {Frzn.Model} - the model the field applies to
     * @param name {string} - the field name
     * @param options {object=} - options describing the field
     */
    var initField = function(model, name, options) {
        Ember.assert("Field name must not be null", name !== null && name !== undefined && name != "");
        if(get(model, '_data').hasOwnProperty(name) === false) {
            options = options || {};
            if(options.isRelationship) {
                setupRelationship(model, name, options)
            } else {
                set(model, '_data.' + name, options.defaultValue);
            }
            var properties = get(model, '_properties');
            if(-1 === properties.indexOf(name)) //do not redefine
                properties.push(name);
        }
        initValidators(model, name, options);
    };

    var getValue = function(model, key) {
        var meta = model.constructor.metaForProperty(key);
        //prepare for reading value: get _data object
        var data = get(model, '_data');
        if(meta.options.isRelationship) {
            //we are dealing with a relationship, so get its definition first
            var rel = get(model, '_relationships.' + key);
            //the real value is the content of the relationship proxy object
            return get(rel, 'content');
        } else {
            //a plain field was requested, get the value from the _data object
            return Ember.getWithDefault(data, key, meta.options.defaultValue);
        }
    };

    var setValue = function(model, key, value) {
        var meta = model.constructor.metaForProperty(key);
        var converter = getConverter(meta.type);
        value = converter.convert(value, meta.options);
        //prepare object: get _data and _backup
        var data = get(model, '_data');
        var backup = get(model, '_backup');
        //the old value is the one already present in _data object
        var oldValue = get(data, key);
        if(meta.options.isRelationship) {
            //we are dealing with a relationship, so get its definition first
            var rel = get(model, '_relationships.' + key);
            //old value is the content of the relationship object
            oldValue = get(rel, 'content');
            //set the parent object in the content
            if(value)
                set(value, '_parent', model);
            //update the value of the relationship
            set(rel, 'content', value);
        } else {
            //update the value of the field
            set(data, key, value);
        }
        //save the old value in the backup object if needed
        if(!get(backup, key))
            set(backup, key, oldValue);
        //mark dirty the field if necessary
        if(oldValue != value)
            markDirty(model, key);
        if(key == model.constructor.idProperty)
            model[key] = value;
        return value;
    };

    var attr = function (type, options) {
        type = type || 'string';
        options = options || {};
        return function (key, value) {
            initField(this, key, options);
            if (arguments.length > 1) {
                //setter
                value = setValue(this, key, value);
            } else {
                //getter
                value = getValue(this, key);
            }
            return value;
        }.property('_data').cacheable(false).meta({type: type, options: options}); //TODO: cacheable is false to allow more complex get operations. I should avoid this...
    };

    window.Frzn.reopenClass({
        /**
         * Utility function to define a model attribute
         * @param type The type of attribute. Default to 'string'
         * @returns a computed property for the given attribute
         * @param options An hash describing the attribute. Accepted values are:
         *      defaultValue: a default value for the field when it is not defined (not valid for relationships)
         */
        attr: attr

    });<commit_msg>id property is no more exposed as a simple object property<commit_after>"use strict";
!function () {
    var get = Ember.get, set = Ember.set, getConverter = Frzn.getConverter, relationships = Frzn.relationships;

    var setupRelationship = function(model, name, options) {
        //For relationships we create a wrapper object using Ember proxies
        if(typeof options.destination == 'string') {
            var dst = get(options.destination);
            if(!dst) {
                var s = options.destination.split('.');
                if(s.length) {
                    dst = Ember.Namespace.byName(s[0]).get(s.slice(1).join('.'));
                }
            }
            options.destination = dst;
        }
        Ember.assert("You must provide a valid model class for field " + name, options.destination != null && options.destination != undefined);
        var rel = relationships[options.relationshipType].create({
            type: options.relationshipType,
            options: options
        });
        var data = get(model, '_data');
        var rels = get(model, '_relationships');
        set(rels, name, rel);
        set(data, name, undefined);
    };

    var initValidators = function(model, name, options) {
        if(options && !$.isEmptyObject(options)) {
            var validators = get(model, '_validators');
            var a = []
            for(var k in options) {
                if(options.hasOwnProperty(k)) {
                    var v = Frzn.createValidator(k, options[k]);
                    if(v) {
                        a.push(v);
                    }
                }
            }
            validators[name] = a;
        }
    };

    /**
     * Initialize a model field. This function tries to understand what kind of attribute should be
     * instantiated, along with converters and relationships.
     *
     * @param model {Frzn.Model} - the model the field applies to
     * @param name {string} - the field name
     * @param options {object=} - options describing the field
     */
    var initField = function(model, name, options) {
        Ember.assert("Field name must not be null", name !== null && name !== undefined && name != "");
        if(get(model, '_data').hasOwnProperty(name) === false) {
            options = options || {};
            if(options.isRelationship) {
                setupRelationship(model, name, options)
            } else {
                set(model, '_data.' + name, options.defaultValue);
            }
            var properties = get(model, '_properties');
            if(-1 === properties.indexOf(name)) //do not redefine
                properties.push(name);
        }
        initValidators(model, name, options);
    };

    var getValue = function(model, key) {
        var meta = model.constructor.metaForProperty(key);
        //prepare for reading value: get _data object
        var data = get(model, '_data');
        if(meta.options.isRelationship) {
            //we are dealing with a relationship, so get its definition first
            var rel = get(model, '_relationships.' + key);
            //the real value is the content of the relationship proxy object
            return get(rel, 'content');
        } else {
            //a plain field was requested, get the value from the _data object
            return Ember.getWithDefault(data, key, meta.options.defaultValue);
        }
    };

    var setValue = function(model, key, value) {
        var meta = model.constructor.metaForProperty(key);
        var converter = getConverter(meta.type);
        value = converter.convert(value, meta.options);
        //prepare object: get _data and _backup
        var data = get(model, '_data');
        var backup = get(model, '_backup');
        //the old value is the one already present in _data object
        var oldValue = get(data, key);
        if(meta.options.isRelationship) {
            //we are dealing with a relationship, so get its definition first
            var rel = get(model, '_relationships.' + key);
            //old value is the content of the relationship object
            oldValue = get(rel, 'content');
            //set the parent object in the content
            if(value)
                set(value, '_parent', model);
            //update the value of the relationship
            set(rel, 'content', value);
        } else {
            //update the value of the field
            set(data, key, value);
        }
        //save the old value in the backup object if needed
        if(!get(backup, key))
            set(backup, key, oldValue);
        //mark dirty the field if necessary
        if(oldValue != value)
            markDirty(model, key);
        return value;
    };

    var attr = function (type, options) {
        type = type || 'string';
        options = options || {};
        return function (key, value) {
            initField(this, key, options);
            if (arguments.length > 1) {
                //setter
                value = setValue(this, key, value);
            } else {
                //getter
                value = getValue(this, key);
            }
            return value;
        }.property('_data').cacheable(false).meta({type: type, options: options}); //TODO: cacheable is false to allow more complex get operations. I should avoid this...
    };

    window.Frzn.reopenClass({
        /**
         * Utility function to define a model attribute
         * @param type The type of attribute. Default to 'string'
         * @returns a computed property for the given attribute
         * @param options An hash describing the attribute. Accepted values are:
         *      defaultValue: a default value for the field when it is not defined (not valid for relationships)
         */
        attr: attr

    });
{'fraction_non_alphanumeric': 0.10811273879893772, 'fraction_numerical': 0.0006853422427824896, 'mean_word_length': 1.8396983702262224, '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': '3776680', 'n_tokens_mistral': 2981, 'n_tokens_neox': 2908, 'n_words': 988}