* 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)
| 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 |
nothing calls this directly
no test coverage detected