Method: Sequel::SQL::BooleanExpression.invert
- Defined in:
- lib/sequel/sql.rb
.invert(ce) ⇒ Object
Invert the expression, if possible. If the expression cannot be inverted, raise an error. An inverted expression should match everything that the uninverted expression did not match, and vice-versa, except for possible issues with SQL NULL (i.e. 1 == NULL is NULL and 1 != NULL is also NULL).
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/sequel/sql.rb', line 463 def self.invert(ce) case ce when BooleanExpression case op = ce.op when :AND, :OR BooleanExpression.new(OPERTATOR_INVERSIONS[op], *ce.args.collect{|a| BooleanExpression.invert(a)}) else BooleanExpression.new(OPERTATOR_INVERSIONS[op], *ce.args.dup) end when ComplexExpression raise(Sequel::Error, "operator #{ce.op} cannot be inverted") else BooleanExpression.new(:NOT, ce) end end |