./lib/ambition/where.rb in ambition-0.1.3 vs ./lib/ambition/where.rb in ambition-0.1.4
- old
+ new
@@ -61,11 +61,11 @@
def process_true(exp)
sanitize 'true'
end
def process_match3(exp)
- regexp, target = exp.shift.last.inspect.gsub('/',''), process(exp.shift)
+ regexp, target = exp.shift.last.inspect.gsub(/\/([^\/]+)\/\S*/, '\1'), process(exp.shift)
"#{target} REGEXP '#{regexp}'"
end
def process_dvar(exp)
target = exp.shift
@@ -119,24 +119,33 @@
'!~'
else
raise "Not implemented: #{method}"
end
end
-
+
def translation(receiver, method, other)
case method.to_s
when '=='
- "#{process(receiver)} = #{process(other)}"
+ case other_value = process(other)
+ when "NULL"
+ "#{process(receiver)} is #{other_value}"
+ else
+ "#{process(receiver)} = #{other_value}"
+ end
when '<>', '>', '<'
"#{process(receiver)} #{method} #{process(other)}"
when 'include?'
"#{process(other)} IN (#{process(receiver)})"
when '=~'
"#{process(receiver)} LIKE #{process(other)}"
when '!~'
"#{process(receiver)} NOT LIKE #{process(other)}"
+ when 'upcase'
+ "UPPER(#{process(receiver)})"
+ when 'downcase'
+ "LOWER(#{process(receiver)})"
else
- extract_includes(receiver, method) || "#{process(receiver)}.`#{method}` #{process(other)}"
+ extract_includes(receiver, method) || "#{process(receiver)}.`#{method}`"
end
end
end
end