Question

I'm looking for a simple way to let users define a set of rules to filter objects.

Eg. let them define something like "notify me about a booking if booking date < 2009/04/30 AND value > 100.00"

More or less: I'd like to have a Ruby rules engine with custom DSL.

Is there a library offering that? Came across Ruleby, but it doesn't support custom DSL, yet.

What's the best apporach to do that?

Was it helpful?

Solution

Take a look at Treetop. You can define your DSL as a Parsing Expression Grammar and then parse it to create your rules in whatever format you like.

OTHER TIPS

Have a look at the wongi-engine gem it is a new rules engine based on the Rete algorithm that is gathering a fair bit of attention lately.

I don't know exactly how and on what objects these rules should be evaluated, but if these are ActiveRecord models maybe Ambition would be way to go. It let's you write conditions in ruby, something like:

User.select { |m| m.name == 'jon' && m.age == 21 }

This gets converted to SQL and you'll get all users satisfying the given criteria

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top