Skip to content

Instantly share code, notes, and snippets.

@mperham
mperham / gist:7d763bdc42465caf17c7
Last active August 29, 2015 14:02
Rule execution

I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:

item.a > 10 && item.b == 0 || item.category == FOOTWEAR

These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:

class Rule