<commit_before>/**
 * @author <a href="http://www.affka.ru"><NAME></a>
 * @license MIT
 */
'use strict';

var Jii = require('../BaseJii');
var Validator = require('./Validator');
class DefaultValueValidator extends Validator {

    preInit() {
        this.skipOnEmpty = false;
        this.value = null;
        super.preInit(...arguments);
    }

    init() {
        super.init();
        if (this.message === null) {
            this.message = ''; // @todo
        }
    }

    validateAttribute(object, attribute) {
        if (this.isEmpty(object.get(attribute))) {
            object.set(attribute, this.value);
        }
    }

}
module.exports = DefaultValueValidator;<commit_msg>fix DefaultValueValidator.js<commit_after>/**
 * @author <a href="http://www.affka.ru"><NAME></a>
 * @license MIT
 */
'use strict';

var Jii = require('../BaseJii');
var Validator = require('./Validator');
var _isArray = require('lodash/isArray');
var _intersection = require('lodash/intersection');
var _map = require('lodash/map');
class DefaultValueValidator extends Validator {

    preInit() {
        this.skipOnEmpty = false;
        this.value = null;
        super.preInit(...arguments);
    }

    init() {
        super.init();
        if (this.message === null) {
            this.message = ''; // @todo
        }
    }

    validateAttribute(object, attribute) {
        if (this.isEmpty(object.get(attribute))) {
            object.set(attribute, this.value);
        }
    }

    validate(object, attributes) {
        attributes = _isArray(attributes) ? _intersection(this.attributes, attributes) : this.attributes;

        var promises = _map(attributes, attribute => {
            if (this.skipOnError && object.hasErrors(attribute)) {
                return;
            }

            return this.validateAttribute(object, attribute);
        });

        return Promise.all(promises);
    }

}
module.exports = DefaultValueValidator;
{'fraction_non_alphanumeric': 0.15174897119341563, 'fraction_numerical': 0.0, 'mean_word_length': 2.4003496503496504, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5919263', 'n_tokens_mistral': 566, 'n_tokens_neox': 553, 'n_words': 107}