On Mar 19, 10:37 am, szimek <
szi...@gmail.com> wrote:
[snip -- I don't have an answer to the first part]
> Also in ez_where I could do something like this:
>
> cond = Caboose::EZ::Condition.new do
> foo == 'bar' unless params[:filter][:country].blank?
> baz <=> (1..5) if something
> end
>
> Is it possible to do something similar in ambition? I.e. if
> params[:filter][:country] == "", I don't want to include it in the
> condition.
I just had to this! You can move the guards outside the Ambition
block, and build the query incrementally:
cond = Condition.select { true }
cond = cond.select { |it| it.foo == 'bar' } unless params[:filter]
[:country].blank?
cond = cond.select { |it| it.baz <=> (1..5) } if something
This constructs an object that generates a single :conditions
expression, even though the expression is sourced in pieces.