deliveredtechnologies / rulebook

100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
http://www.deliveredtechnologies.com
Apache License 2.0
717 stars 124 forks source link

I'd like to have a RuleRunner but add Rules one by one #161

Closed mikelear closed 5 years ago

mikelear commented 5 years ago

Hi , is it possible to have a RuleRunner but only add Rules individually , so instead of scanning a package you add the POJO Rule by calling something like .addRule( Rule ). I've done this using CoRRuleBook and then RuleAdapter but the Rule isn't Audited so it looks like I will have to create another RuleRunner , seems like this might be something worth adding. Happy to do this but just wanted to make sure I'm not missing something obvious that is already there.

mikelear commented 5 years ago

Looks like there is in fact an easy way to do this

// Were the class FirstName is a POJO Rule @Rule AuditableRule auditRule = new AuditableRule( new RuleAdapter( new FirstName() ) ); RuleBook ruleBook = new RuleBookAuditor<>( new CoRRuleBook<>()); ruleBook.addRule( auditRule ); Auditor auditor = (Auditor)getCase( id ).ruleBook; ruleBook.run( facts );

happy to write an example if people think this is something people would find useful

Clayton7510 commented 5 years ago

Yep, that should do it. POJO rules are auto loaded by a RuleBookRunner. But you can also add POJO rules to RuleBooks manually as you pointed out - RuleAdapter adapts a POJO rule to a rule that could be used in any RuleBook.