# all files / keystone/lib/list/ underscoreMethod.js

100% Statements 11/11
100% Branches 2/2
100% Functions 2/2
100% Lines 10/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    1×
    215×
    215×
    215×
    215×
    262×
    262×

    215×
    215×

    1×
     /**
     * Adds a method to the underscoreMethods collection on the list, which is then
     * added to the schema before the list is registered with mongoose.
     */
    function underscoreMethod (path, fn) {
    	var target = this.underscoreMethods;
    	path = path.split('.');
    	var last = path.pop();
    	path.forEach(function (part) {
    		if (!target[part]) target[part] = {};
    		target = target[part];
    	});
    	target[last] = fn;
    	return this;
    }

    module.exports = underscoreMethod;