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

Support for array of string inputs in conditions and consequences #6

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/node-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@ RuleEngine.prototype.execute = function (fact,callback) {

var outcome = true;

//If user gives condiotns as string we can able to execute the rules using the eval function

if(typeof _rules[x].condition != 'function')
_rules[x].condition = eval('('+ _rules[x].condition + ')');

_rulelist = _.flatten([_rules[x].condition]);

(function looprules(y) {


if(y < _rulelist.length) {

if(typeof _rulelist[y] === 'string')
_rulelist[y] = eval('('+ _rulelist[y] + ')');

_rulelist[y].call({}, session,function(out){
_rulelist[y].call({}, session,function(out){

outcome = outcome && out;
process.nextTick(function(){
Expand All @@ -63,15 +60,15 @@ RuleEngine.prototype.execute = function (fact,callback) {

if (outcome) {

if(typeof _rules[x].consequence != 'function')
_rules[x].consequence = eval('('+ _rules[x].consequence + ')');

_consequencelist = _.flatten([_rules[x].consequence]);

(function loopconsequence(z) {

if(z < _consequencelist.length) {

if(typeof _consequencelist[z] === 'string')
_consequencelist[z] = eval('('+ _consequencelist[z] + ')');

_consequencelist[z].apply(session, [function() {

if (!_.isEqual(last_session,session)) {
Expand Down