Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rules that pass when finding facts, or give an error otherwise #88

@mannerheim77

Description

@mannerheim77

I need to run a ruleset, and for each rule that doesn't pass, I need to know why (via error message). Is it possible to implement rules which pass when finding facts, but generate an error when they don't? At first I thought it was a simple as this:

engine = Wongi::Engine.create
debit_rule = engine.rule "transaction type is debit" do
   forall {
     has :TRANSACTION, :transaction_type, :TX_TYPE
     equal :TX_TYPE, 2
   }
   make {
     error "Transaction is not a debit"
   }
end

engine << ["A", :transaction_type, 1]

But after scratching my head for a while, I eventually learned that this will throw an error if the forall finds those facts. I could negate the conditions in the forall, but I'd really rather have the conditions in the positive, since I feel like it reads better.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions