Rule sets
Rule sets are a convenient way to separate your business rules into different collections.
Doing so increases the rules' maintainability because of a better organization and fully uncoupled rules.
Tip
Rule sets are very usefull when you have a lot of rules.
Info
Most of the time, you won't need to handle different rule sets and will only use the default one: default_rule_set
.
The good news is that different rule sets can be used seamlessly with the same rules engine instance
Let's take the following example:
Based on that example, imagine that you need to add some rules about something totally different than the superhero school. Let's say rules for a dinosaur school.
Configuration
Update your configuration by adding a new rule set: dinosaur_school_set
- Add your new set of rules under the
rules
key - Regular condition configuration, nothing new here
Good to know
You can define your rule sets into different YAML files (under the rules
key in each).
Usage
Now that your rule sets are defined (and assuming that your condition and action functions are implemented in the right modules), you can easily use them:
- Select the rule set that you want to use when applying rules on your input data.
Good to know
Input data can be different or the same among the rule sets. It depends on the use case.
Object-Oriented Model
classDiagram
rule_set "1" -- "1..*" rule_group
rule_group "1" -- "1..*" rule
rule "1..*" -- "0..*" condition
rule "1..*" -- "1" action