Ruby & Rules Engines

心已入冬 提交于 2019-11-27 12:25:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!