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

Method constructor

src/rule.js:21–44  ·  view source on GitHub ↗

* returns a new Rule instance * @param {object,string} options, or json string that can be parsed into options * @param {integer} options.priority (>1) - higher runs sooner. * @param {Object} options.event - event to fire when rule evaluates as successful * @param {string} options.event.

(options)

Source from the content-addressed store, hash-verified

19 * @return {Rule} instance
20 */
21 constructor (options) {
22 super()
23 if (typeof options === 'string') {
24 options = JSON.parse(options)
25 }
26 if (options && options.conditions) {
27 this.setConditions(options.conditions)
28 }
29 if (options && options.onSuccess) {
30 this.on('success', options.onSuccess)
31 }
32 if (options && options.onFailure) {
33 this.on('failure', options.onFailure)
34 }
35 if (options && (options.name || options.name === 0)) {
36 this.setName(options.name)
37 }
38
39 const priority = (options && options.priority) || 1
40 this.setPriority(priority)
41
42 const event = (options && options.event) || { type: 'unknown' }
43 this.setEvent(event)
44 }
45
46 /**
47 * Sets the priority of the rule

Callers

nothing calls this directly

Calls 4

setConditionsMethod · 0.95
setNameMethod · 0.95
setPriorityMethod · 0.95
setEventMethod · 0.95

Tested by

no test coverage detected