tags:

views:

963

answers:

2

Hi there,

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?

Thanks!

Matt

+1  A: 

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.

Ian Terrell
Hithanks for answer. Treetop really looks like a solution. Do you have a link for any best practices website maybe? Hard to find good stuff on the net.I was thinking about the following approach:- Let users define their rules- Parse these using Treetop- Create Ruby code based on these rules - feed these into Ruleby- filter my objects using the rules engineDoes that sound too freaky?
Matt
Unfortunately I haven't had much luck finding resources on Treetop either. But your solution sounds like the right approach. Best of luck!
Ian Terrell
+1  A: 

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

esad