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

Method evaluateRules

src/engine.js:237–256  ·  view source on GitHub ↗

* Runs an array of rules * @param {Rule[]} array of rules to be evaluated * @return {Promise} resolves when all rules in the array have been evaluated

(ruleArray, almanac)

Source from the content-addressed store, hash-verified

235 * @return {Promise} resolves when all rules in the array have been evaluated
236 */
237 evaluateRules (ruleArray, almanac) {
238 return Promise.all(ruleArray.map((rule) => {
239 if (this.status !== RUNNING) {
240 debug(`engine::run status:${this.status}; skipping remaining rules`)
241 return Promise.resolve()
242 }
243 return rule.evaluate(almanac).then((ruleResult) => {
244 debug(`engine::run ruleResult:${ruleResult.result}`)
245 almanac.addResult(ruleResult)
246 if (ruleResult.result) {
247 almanac.addEvent(ruleResult.event, 'success')
248 return this.emitAsync('success', ruleResult.event, almanac, ruleResult)
249 .then(() => this.emitAsync(ruleResult.event.type, ruleResult.event.params, almanac, ruleResult))
250 } else {
251 almanac.addEvent(ruleResult.event, 'failure')
252 return this.emitAsync('failure', ruleResult.event, almanac, ruleResult)
253 }
254 })
255 }))
256 }
257
258 /**
259 * Runs the rules engine

Callers 1

runMethod · 0.95

Calls 5

debugFunction · 0.85
allMethod · 0.80
addResultMethod · 0.80
addEventMethod · 0.80
evaluateMethod · 0.45

Tested by

no test coverage detected