Politics, Programming and Possibilities
28 Jun
Thanks to Pawel Kondzior, there’s a little bug fix for the condition builder. Previously, making multiple “OR” blocks would make “AND” blocks instead:
Condition.block do |t|
t.or do |u|
u.and "b", 1
u.and "c", 2
end
t.or do |v|
v.and "d", 3
end
end
# => ["(b = ? AND c = ?) AND (d = ?)", 1, 2, 3]
Now, as expected, it produces:
# => ["(b = ? AND c = ?) OR (d = ?)", 1, 2, 3]
Download here: Condition Builder 1.1
5 Responses for "Condition Builder 1.1"
[...] Condition Builder 1.1 - a cute way to construct SQL conditions. [...]
Bug fix for empty sub groups:
def block(&block)
result = self.class.new(&block)
@args
Enhancement to handle nil as an condition.
when 1
if values.last == nil
left << “#{column} IS NULL”
else
if values.last.is_a?(Array)
left << “#{column} IN (?)”
else
left << “#{column} = ?”
end
right << values.last
end
Escape version of earlier bug fix:
def block(&block)
result = self.class.new(&block)
@args << result unless result.args.empty?
end
This looks just like what i need, thanks!
BTW, your zip includes your .svn data — you might want to do an ‘export’ next time and zip that up.
Leave a reply