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

Method evaluateCondition

src/rule.js:209–238  ·  view source on GitHub ↗
(condition)

Source from the content-addressed store, hash-verified

207 * @return {Promise(true|false)} - resolves with the result of the condition evaluation
208 */
209 const evaluateCondition = (condition) => {
210 if (condition.isConditionReference()) {
211 return realize(condition)
212 } else if (condition.isBooleanOperator()) {
213 const subConditions = condition[condition.operator]
214 let comparisonPromise
215 if (condition.operator === 'all') {
216 comparisonPromise = all(subConditions)
217 } else if (condition.operator === 'any') {
218 comparisonPromise = any(subConditions)
219 } else {
220 comparisonPromise = not(subConditions)
221 }
222 // for booleans, rule passing is determined by the all/any/not result
223 return comparisonPromise.then((comparisonValue) => {
224 const passes = comparisonValue === true
225 condition.result = passes
226 return passes
227 })
228 } else {
229 return condition
230 .evaluate(almanac, this.engine.operators)
231 .then((evaluationResult) => {
232 const passes = evaluationResult.result
233 condition.factResult = evaluationResult.leftHandSideValue
234 condition.result = passes
235 return passes
236 })
237 }
238 }
239
240 /**
241 * Evalutes an array of conditions, using an 'every' or 'some' array operation

Callers

nothing calls this directly

Calls 3

isConditionReferenceMethod · 0.80
isBooleanOperatorMethod · 0.80
evaluateMethod · 0.45

Tested by

no test coverage detected