./lib/ambition/where.rb in ambition-0.1.5 vs ./lib/ambition/where.rb in ambition-0.1.6
- old
+ new
@@ -28,13 +28,20 @@
def process_or(exp)
joined_expressions 'OR', exp
end
def process_not(exp)
- _, receiver, method, other = *exp.first
+ type, receiver, method, other = *exp.first
exp.clear
- return translation(receiver, negate(method), other)
+
+ case type
+ when :call
+ translation(receiver, negate(method, other), other)
+ when :match3
+ regexp = receiver.last
+ "#{process(method)} #{statement(:negated_regexp, regexp)} #{sanitize(regexp)}"
+ end
end
def process_call(exp)
receiver, method, other = *exp
exp.clear
@@ -61,12 +68,12 @@
def process_true(exp)
sanitize 'true'
end
def process_match3(exp)
- regexp, target = exp.shift.last.inspect.gsub(/\/([^\/]+)\/\S*/, '\1'), process(exp.shift)
- "#{target} REGEXP '#{regexp}'"
+ regexp, target = exp.shift.last, process(exp.shift)
+ "#{target} #{statement(:regexp, regexp)} #{sanitize(regexp)}"
end
def process_dvar(exp)
target = exp.shift
if target == @receiver
@@ -109,26 +116,32 @@
def value(variable)
sanitize eval(variable, @block)
end
- def negate(method)
+ def negate(method, target = nil)
+ if Array(target).last == [:nil]
+ return 'IS NOT'
+ end
+
case method
when :==
'<>'
when :=~
'!~'
else
- raise "Not implemented: #{method}"
+ raise "Not implemented: #{method.inspect}"
end
end
- def translation(receiver, method, other)
+ def translation(receiver, method, other = nil)
case method.to_s
+ when 'IS NOT'
+ "#{process(receiver)} IS NOT #{process(other)}"
when '=='
case other_value = process(other)
when "NULL"
- "#{process(receiver)} is #{other_value}"
+ "#{process(receiver)} IS #{other_value}"
else
"#{process(receiver)} = #{other_value}"
end
when '<>', '>', '<', '>=', '<='
"#{process(receiver)} #{method} #{process(other)}"