Git Product home page Git Product logo

Comments (10)

LvelezH avatar LvelezH commented on May 20, 2024 1

Hi, and thanks for the fast response :)
I had already started implementing it storing stuff in the "facts", and it's working correctly. Auditing would be great, if it comes I will probably change the way I run my rules.

Thanks again, and kudos for the great lib :)

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

Your concern is actually addressed in Issue #38.

But to answer your question... No, 'else' is not available for a rule. The decision not to allow for rules firing on 'else' was intentional. The idea being that each rule is an independent action that executes given some specific state. There was also a concern that building out if/then/else logic could lead to nesting rules and basically creating the exact kind of conditional branching chain complexity that rules are intended to address.

Still, there are some approaches you 'could' use.

  1. Change your way of thinking [slightly]. Make every rule simply an action that executes based on some required or expected state. I think you'll find thinking this way about rules greatly simplifies the organization and maintenance of rules.

  2. Use a Fact to store stuff that doesn't make it to the 'then' logic. It's not elegant, but you can do this, even in the 'when' statement.

  3. Have a rule that fires on negative logic. Again, this is not elegant. But it is one way to achieve what you are trying to do.

Auditing is coming that should address your need - allow you to determine which rules fired and which ones didn't. But there are some other things on deck before it - I've got to put a bow on thread safety for POJO rules and my time commitments at work have increased a bit, which takes some time away from RuleBook.

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

@LvelezH auditing is currently available in 0.9-SNAPSHOT. Auditing will allow you to determine which rules were run, and which rules were not run. Here's a link that explains how you can use the snapshot repository in your project: https://github.com/rulebook-rules/rulebook/wiki/Download-and-Install.

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

The plan is to have 0.9 released to Maven central within the next week or two. For an explanation on how to enable and use auditing, check out the README in this branch: https://github.com/rulebook-rules/rulebook/tree/Issue38_RulesAudit

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

The current snapshot 0.9-SNAPSHOT is released to the sonatype snapshot repo. Assuming no issues, this snapshot release will become the 0.9 release in Maven Central shortly. It will contain rules auditing.

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

After further consideration, I think adding "orElse" to the DSL might be a good idea. The "orElse" could create a rule action based on the negative condition. This would still make each rule an independent assertion.

As far as POJO Rules are concerned, I don't think an orElse is either needed, nor would it be a good idea - it would just make things more complicated and messy, IMO.

from rulebook.

ruchichhabra009 avatar ruchichhabra009 commented on May 20, 2024

@Clayton7510
Any example for OrElse in DSL? I am planning to create child of GoldenRule Class and have custom ELSE method which will be called when the condition returns true. I am not sure if that will be better approach. As you are pretty familiar with the code, can you suggest?
Thanks

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

I think first, have it work in the Rules - add it to the interface and put the functionality in GoldenRule so that when the "when" condition was not true, an OrElse action would fire. Then, the DSL could be modified to streamline building the OrElse action. Finally, an @orElse annotation should be added for POJO rules.

I also think that OrElse should only support a single action, whereas Then supports multiple actions that are chained together.

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

Else is coming to Rules. v0.11 is targeted for Else rules at the moment.

from rulebook.

Clayton7510 avatar Clayton7510 commented on May 20, 2024

Actually, it's looking more like v0.12

from rulebook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.