rule generator

8 views
Skip to first unread message

sebd...@gmail.com

unread,
Aug 3, 2009, 9:13:49 AM8/3/09
to Ruleby
hi,

For Rails Commerce http://rails-commerce.com we want to make a rule
generator like Magento.
We want to build rule's conditions with a html form and pass some
variables in the rule to special offers or shipping methods selection.

For this we need to store rule's condition in database as string, we
think that the tiger DSL is appropriate.

Store Ferrari syntax in database is synonym of eval store strings in
rule execution like :

rule = Rule.first
puts rule.condition
=>"[Product, :p, { :discount => 10 }, m.weight >= 15, m.name ==
'IPhone' ]"

rule rule.id.to_sym, eval(rule.condition) do |v|
v[:p].price -= v[:discount]
end

Do you think the tiger DSL still deprecated in future versions of
Ruleby ?
Because it's more safe to store tiger syntax in database and don't
eval it like :

puts rule.condition
=> "Product as :p where #weight >= 15 #&& #name == 'IPhone'"

If it is the case how do you think we can store rule's condition in a
database ?


Thanks.

Matt Smith

unread,
Aug 4, 2009, 7:29:45 AM8/4/09
to rul...@googlegroups.com
Hi Sebastien,

I understand what you are trying to accomplish.  Work was started on an external DSL some time ago, but it was never finished.  It was to be based similar to the string syntax based DSL.  Recently I have started working on a engine for Rails that has an ActiveRecord based model for Rules, but as you have pointed out you must use eval with the rule condition.  My plan to solve this problem is to write a parser for the condition, but neither are complete.  I will update the ActiveRule repo shortly with what I have so far. 

Thanks,

Matt

sebd...@gmail.com

unread,
Aug 4, 2009, 9:37:06 AM8/4/09
to Ruleby
Hi Matt,

Thanks for your answer !

Is LeTigre DSL less complete than the Ferrary DSL ?

Why LeTigre DSL is deprecated ?

Thanks,

Sebastien

On Aug 4, 1:29 pm, Matt Smith <codeaspe...@gmail.com> wrote:
> Hi Sebastien,
>
> I understand what you are trying to accomplish.  Work was started on an
> external DSL some time ago, but it was never finished.  It was to be based
> similar to the string syntax based DSL.  Recently I have started working on
> a engine for Rails that has an ActiveRecord based model for Rules, but as
> you have pointed out you must use eval with the rule condition.  My plan to
> solve this problem is to write a parser for the condition, but neither are
> complete.  I will update the ActiveRule repo shortly with what I have so
> far.
>
> Thanks,
>
> Matt
>
> On Mon, Aug 3, 2009 at 8:13 AM, sebastien.del...@webpulser.com <
>
> sebdel...@gmail.com> wrote:
>
> > hi,
>
> > For Rails Commercehttp://rails-commerce.comwe want to make a rule

Joe Kutner

unread,
Aug 4, 2009, 4:22:24 PM8/4/09
to rul...@googlegroups.com
Hi Sebastien,

Yes, the Le Tigre DSL is less complete. Basically, we were using
regular expressions to parse the strings, and we could only take that
so far. When we started to implement for complicated features, the
whole this just fell apart. I suspect the more basic features still
work, but i have not tried them.

Thanks for the interest

Joe

cyrill62

unread,
Aug 6, 2009, 10:58:30 AM8/6/09
to Ruleby
Hi,

In the context of a rule generator, how can I pass a variable in the
rule, like :

rule :test, [Product, :product, { 15 => :discount }, m.price > 50] do |
context|
context[:product].price -= context[:discount]
modify context[:product]
end

Thanks.

Joe Kutner

unread,
Aug 6, 2009, 9:53:17 PM8/6/09
to rul...@googlegroups.com
The context isn't really designed to have static values added to it.
That's part of why the order of the key/value is reversed (in a true
hash it would of course be :discount => 15). Instead, you have to
think of the context as a separate Hash from what you defined in the
rule.

Is there a reason you need to put the static value in the
left-hand-side of the rule? On the surface, it seems like you could
just put it in the right-hand-side.

I would of course welcome a patch that enables this sort thing.

Matt Smith

unread,
Aug 7, 2009, 1:34:22 AM8/7/09
to rul...@googlegroups.com
Hi Sebatien,

I have updated the ActiveRule repo with the beginnings of an ActiveRecord based model for Rules.  Very early at this point, but thought it might be of interest.
It uses eval in two places, type and cond.  I would like to replace those two with a parser to avoid the eval.

http://github.com/mattup/activerule/tree/master

Thanks,

Matt
Reply all
Reply to author
Forward
0 new messages