|
@ -148,37 +148,40 @@ Ruler.prototype.push = function (ruleName, fn, options) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Enable list of rules by names. If `strict` is true, then all non listed
|
|
|
// Enable rules by names.
|
|
|
// rules will be disabled.
|
|
|
|
|
|
//
|
|
|
//
|
|
|
Ruler.prototype.enable = function (list, strict) { |
|
|
Ruler.prototype.enable = function (list, ignoreInvalid) { |
|
|
if (!Array.isArray(list)) { |
|
|
if (!Array.isArray(list)) { list = [ list ]; } |
|
|
list = [ list ]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// In strict mode disable all existing rules first
|
|
|
|
|
|
if (strict) { |
|
|
|
|
|
this.__rules__.forEach(function (rule) { |
|
|
|
|
|
rule.enabled = false; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Search by name and enable
|
|
|
// Search by name and enable
|
|
|
list.forEach(function (name) { |
|
|
list.forEach(function (name) { |
|
|
var idx = this.__find__(name); |
|
|
var idx = this.__find__(name); |
|
|
|
|
|
|
|
|
if (idx < 0) { throw new Error('Rules manager: invalid rule name ' + name); } |
|
|
if (idx < 0) { |
|
|
|
|
|
if (ignoreInvalid) { return; } |
|
|
|
|
|
throw new Error('Rules manager: invalid rule name ' + name); |
|
|
|
|
|
} |
|
|
this.__rules__[idx].enabled = true; |
|
|
this.__rules__[idx].enabled = true; |
|
|
|
|
|
|
|
|
}, this); |
|
|
}, this); |
|
|
|
|
|
|
|
|
this.__cache__ = null; |
|
|
this.__cache__ = null; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Disable list of rules by names.
|
|
|
// Enable rules by whitelisted names (others will be disables).
|
|
|
//
|
|
|
//
|
|
|
Ruler.prototype.disable = function (list) { |
|
|
Ruler.prototype.enableOnly = function (list, ignoreInvalid) { |
|
|
|
|
|
if (!Array.isArray(list)) { list = [ list ]; } |
|
|
|
|
|
|
|
|
|
|
|
this.__rules__.forEach(function (rule) { rule.enabled = false; }); |
|
|
|
|
|
|
|
|
|
|
|
this.enable(list, ignoreInvalid); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Disable rules by names.
|
|
|
|
|
|
//
|
|
|
|
|
|
Ruler.prototype.disable = function (list, ignoreInvalid) { |
|
|
if (!Array.isArray(list)) { |
|
|
if (!Array.isArray(list)) { |
|
|
list = [ list ]; |
|
|
list = [ list ]; |
|
|
} |
|
|
} |
|
@ -187,9 +190,11 @@ Ruler.prototype.disable = function (list) { |
|
|
list.forEach(function (name) { |
|
|
list.forEach(function (name) { |
|
|
var idx = this.__find__(name); |
|
|
var idx = this.__find__(name); |
|
|
|
|
|
|
|
|
if (idx < 0) { throw new Error('Rules manager: invalid rule name ' + name); } |
|
|
if (idx < 0) { |
|
|
|
|
|
if (ignoreInvalid) { return; } |
|
|
|
|
|
throw new Error('Rules manager: invalid rule name ' + name); |
|
|
|
|
|
} |
|
|
this.__rules__[idx].enabled = false; |
|
|
this.__rules__[idx].enabled = false; |
|
|
|
|
|
|
|
|
}, this); |
|
|
}, this); |
|
|
|
|
|
|
|
|
this.__cache__ = null; |
|
|
this.__cache__ = null; |
|
|