Determining which rule matched and how often...

39 views
Skip to first unread message

Mel Riffe

unread,
Feb 29, 2012, 9:11:10 PM2/29/12
to rul...@googlegroups.com
Howdy Folks,

For testing/debugging purposes, is there a way to know how often a rule has matched?

We're using Ruleby to enforce some data integrity rules and I thought'd it be nice to be able to assert, for a given set of data, that a particular rule is matched x number of times.

Thanks for any guidance you can offer.

Cheers,
Mel

Joe Kutner

unread,
Mar 2, 2012, 3:20:10 PM3/2/12
to Ruleby
I'll assume you want something better than adding
GLOBAL_COUNT[:my_rule] +=1 to the right-hand-side of the rule :)

There isn't anything built into the engine that would allow you to do
this, but there is an internal mechanism that collects the matched
rules. You can see this in the TerminalNode here:
https://github.com/Codalytics/ruleby/blob/master/lib/core/nodes.rb#L964

An Activation represents a matched rule. Right now, they don't care
what the name of the rule is, so it might be hard to glean from the
object which one it is. But it could be easily added as an arg here:
https://github.com/Codalytics/ruleby/blob/master/lib/core/engine.rb#L54

If you are really interested in having this I suggest submitting a
patch. The Engine could keep a count of rules that were fired here:
https://github.com/Codalytics/ruleby/blob/master/lib/core/engine.rb#L257

Then we could call an engine.get_fire_count(rule_id) method. I would
gladly accept something like that.

Joe

Kristian Mandrup

unread,
Mar 4, 2012, 6:48:58 AM3/4/12
to Ruleby
Yeah, would be nice with more metadata for the engine :)
Reply all
Reply to author
Forward
0 new messages