MCPcopy
hub / github.com/CacheControl/json-rules-engine / addRule

Method addRule

src/engine.js:45–60  ·  view source on GitHub ↗

* Add a rule definition to the engine * @param {object|Rule} properties - rule definition. can be JSON representation, or instance of Rule * @param {integer} properties.priority (>1) - higher runs sooner. * @param {Object} properties.event - event to fire when rule evaluates as successful

(properties)

Source from the content-addressed store, hash-verified

43 * @param {Object} properties.conditions - conditions to evaluate when processing this rule
44 */
45 addRule (properties) {
46 if (!properties) throw new Error('Engine: addRule() requires options')
47
48 let rule
49 if (properties instanceof Rule) {
50 rule = properties
51 } else {
52 if (!Object.prototype.hasOwnProperty.call(properties, 'event')) throw new Error('Engine: addRule() argument requires "event" property')
53 if (!Object.prototype.hasOwnProperty.call(properties, 'conditions')) throw new Error('Engine: addRule() argument requires "conditions" property')
54 rule = new Rule(properties)
55 }
56 rule.setEngine(this)
57 this.rules.push(rule)
58 this.prioritizedRules = null
59 return this
60 }
61
62 /**
63 * update a rule in the engine

Callers 15

setupFunction · 0.95
setupFunction · 0.95
constructorMethod · 0.95
updateRuleMethod · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95
startFunction · 0.95

Calls 1

setEngineMethod · 0.80

Tested by 13

setupFunction · 0.76
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
setupFunction · 0.64
simpleSetupFunction · 0.64