问题
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?
回答1:
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.
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/820259/ruby-rules-engines