Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends API to return rule info and matched rule chain #47

Merged
merged 1 commit into from
Jun 11, 2016

Conversation

pdapel
Copy link
Contributor

@pdapel pdapel commented May 17, 2016

This PR adds two simple features.

The first feature is lifted from the un-merged suggestions by @escape-llc at #39. Namely, adding a rule() method to the API inside .execute(), so that rule information can be accessed inside the consequence, like so:

"consequence": function(R) {
    this.result = true;
    this.ruleName = R.rule().name;
    this.ruleID = R.rule().id;
    R.stop();
}

The second feature is something I needed for my implementation, namely the list of matched rules in matched order. In my case, the rules are defined by others, and when they get unexpected/undesirable results through the rule engine, this helps them understand how the rules got processed. The list of matched rules is an array named .matchPath, attached to the callback results from .execute(). The array values are the matched rule's .id property, or .name property, or active rule index position, in that order of preference.

I included some simple tests and appended them to the existing describe block for .execute()

  • lib/node-rules.js:
    • adds rule() to .execute API to access rule().name, rule().id, etc
    • adds var matchPath array to hold the chain of matched rule references (by id, or by name, or by active rule index)
    • decorates returned session in final callback with .matchPath
  • test/index.js:
    • adds test to .execute block: "should provide access to rule definitions via rule()"
    • adds test to .execute block: "should include the matched rule path"

* lib/node-rules.js:
   - adds rule() to .execute API to access rule().name, rule().id, etc
   - adds var matchPath array to hold the chain of matched rule references (by id, or by name, or by active rule index)
   - decorates returned session in final callback with .matchPath

* test/index.js:
   - adds test to .execute block: "should provide access to rule definitions via rule()"
   - adds test to .execute block: "should include the matched rule path"

Adds matching rule list, and test cases

* lib/node-rules.js:
   - adds var matchPath array to hold the chain of matched rule references (by id, or by name, or by active rule index)
   - decorates returned session in final callback with .matchPath

* test/index.js:
   - adds test to .execute block: "should provide access to rule definitions via rule()"
   - adds test to .execute block: "should include the matched rule path"
@kevdowney
Copy link

Can we get this merged? We could use this in our project. Thanks.

@mithunsatheesh mithunsatheesh merged commit 986beb0 into mithunsatheesh:master Jun 11, 2016
@kevdowney
Copy link

Can you bump the versioning?

@psingh4
Copy link

psingh4 commented Jun 13, 2016

We pulled the latest from the master. this change is very helpful! thanks!

@escape-llc
Copy link

very welcomed!

Date: Mon, 13 Jun 2016 11:25:58 -0700
From: [email protected]
To: [email protected]
CC: [email protected]; [email protected]
Subject: Re: [mithunsatheesh/node-rules] Extends API to return rule info and matched rule chain (#47)

We pulled the latest from the master. this change is very helpful! thanks!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@sandy-adi
Copy link

@mithunsatheesh I think these changes have not been published to npm. Could you please do it, it would be very helpful.

@mithunsatheesh
Copy link
Owner

Done! Sorry for the delay

@sandy-adi
Copy link

Thank you @mithunsatheesh @pdapel and @escape-llc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants