2

I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be many):

CONDITIONS: (IF)
1)  title = 'some*'
2)  user = 'john'
OUTCOME: (THEN)
1)  e-mail me
2)  deny request

so in the rule above if a request is made input?title='something'&user='john'&...

it would deny the request and e-mail the user since it matches the condition. if the request is input?title='blah'&user='john' it would allow it to pass since it doesn't match any rules.

I found two ways of doing this but I'm not too happy with it and hoping someone else might have a better solution.

First method

  1. When a user creates a rule it generates a temp file where it writes that rule into a programming language of IF THEN statements
  2. When a new request comes in, it goes through that user's rule-list in the programming language and does the appropriate actions

Second method

  1. When a new request comes in, it gets written into a db
  2. We pull all the conditionals from the db for different rules and run a query against that one row to see if it matches the conditions. If it does, we pass along the outcomes to the script to do the rest

I'm not happy with either of these days. Any insight or help here is much appreciated.

  • 1
    You are looking at implementing a rules engine from scratch. You will likely find it easier to use one of the existing ones. – user40980 Feb 26 '16 at 17:42
  • what this has to do with c++? – BЈовић Feb 26 '16 at 18:11
  • @MichaelT do you know of one that I can look at? I had a tough time searching and finding one – Jason K Feb 26 '16 at 18:22
  • Category:Rule engines from Wikipedia. – user40980 Feb 26 '16 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.