all files / montage/core/meta/ validation-semantics.js

31.58% Statements 6/19
100% Branches 0/0
0% Functions 0/8
31.58% Lines 6/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                                                                                                                                                                                                
var Montage = require("../core").Montage;
// TODO kriskowal: massage selectors and FRB together
var Semantics = Montage;
// var Semantics = (require)("core/selector/semantics").Semantics;
var deprecate = require("../deprecate"),
    logger = require("../logger").logger("objectDescriptor");
 
 
/**
 * @class PropertyValidationSemantics
 * @extends Semantics
 */
var PropertyValidationSemantics = exports.PropertyValidationSemantics = Semantics.specialize( /** @lends PropertyValidationSemantics# */ {
 
    /**
     * Create a new semantic evaluator with the object descriptor.
     * @function
     * @param {ObjectDescriptor} objectDescriptor
     * @returns itself
     */
    initWithObjectDescriptor: {
        value: function (objectDescriptor) {
            this._objectDescriptor = objectDescriptor;
            return this;
        }
    },
 
    _objectDescriptor: {
        value: undefined
    },
 
    /**
     * Component description attached to this validation rule.
     */
    objectDescriptor: {
        get: function () {
            return this._objectDescriptor;
        }
    },
 
    /**
     * Compile the syntax tree into a function that can be used for evaluating
     * this selector.
     * @function
     * @param {Selector} selector syntax
     * @returns function
     */
    compile: {
        value: function (syntax, parents) {
            Semantics.compile.call(this, syntax, parents);
        }
    },
 
    operators: {
        value: {
            isBound: function (a) {
                return !a;
            }
        }
    },
 
    evaluators: {
        value: {
            isBound: function (collection, modify) {
                var self = this;
                return function (value, parameters) {
                    value = self.count(collection(value, parameters));
                    return modify(value, parameters);
                };
            }
        }
    },
 
    /*****************************************************************
     * Deprecated Methods
     */
 
    /**
     * @deprecated
     * Create a new semantic evaluator with the object descriptor.
     * @function
     * @param {ObjectDescriptor} objectDescriptor
     * @returns itself
     */
    initWithBlueprint: {
        value: deprecate.deprecateMethod(void 0, function (blueprint) {
            return this.initWithObjectDescriptor(blueprint);
        }, "initWithBlueprint", "initWithObjectDescriptor")
    },
 
    /**
     * @deprecated
     * Component description attached to this validation rule.
     */
    blueprint: {
        get: deprecate.deprecateMethod(void 0, function () {
            return this._blueprint;
        }, "blueprint", "objectDescriptor")
    }
 
});
 
for (var operator in Semantics.operators) {
    PropertyValidationSemantics.operators[operator] = Semantics.operators[operator];
}
 
for (var evaluator in Semantics.evaluators) {
    PropertyValidationSemantics.evaluators[evaluator] = Semantics.evaluators[evaluator];
}