Class: DataMapper::Query::Conditions::NotOperation

Inherits:
AbstractOperation show all
Defined in:
lib/dm-core/query/conditions/operation.rb

Overview

class OrOperation

Instance Attribute Summary

Attributes inherited from AbstractOperation

#operands, #parent

Instance Method Summary collapse

Methods inherited from AbstractOperation

#clear, descendants, #difference, #each, #empty?, #first, inherited, #intersection, #merge, #one?, slug, #slug, #sorted_operands, #union, #valid?

Methods included from Equalizer

#equalize

Methods included from Assertions

#assert_kind_of

Instance Method Details

#<<(operand) ⇒ self

Add an operand to the operation

This will only allow a single operand to be added.

Parameters:

Returns:

  • (self)

    the operation



561
562
563
564
565
# File 'lib/dm-core/query/conditions/operation.rb', line 561

def <<(operand)
  assert_one_operand(operand)
  assert_no_self_reference(operand)
  super
end

#matches?(record) ⇒ true

Match the record

Parameters:

  • record (Resource, Hash)

    the resource to match

Returns:

  • (true)

    true if the record matches, false if not



545
546
547
548
# File 'lib/dm-core/query/conditions/operation.rb', line 545

def matches?(record)
  operand = self.operand
  operand.respond_to?(:matches?) ? !operand.matches?(record) : true
end

#minimizeself, ...

Minimize the operation

Returns:



585
586
587
588
589
590
591
592
# File 'lib/dm-core/query/conditions/operation.rb', line 585

def minimize
  minimize_operands
  prune_operands

  # factor out double negatives if possible
  operand = self.operand
  one? && instance_of?(operand.class) ? operand.operand : self
end

#negated?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test if the operation is negated

Defaults to return false.

Returns:

  • (Boolean)

    true if the operation is negated, false if not



612
613
614
615
# File 'lib/dm-core/query/conditions/operation.rb', line 612

def negated?
  parent = self.parent
  parent ? !parent.negated? : true
end

#operandAbstractOperation, ...

Return the only operand in the operation

Returns:



573
574
575
# File 'lib/dm-core/query/conditions/operation.rb', line 573

def operand
  first
end

#to_sString

Return the string representation of the operation

Returns:

  • (String)

    the string representation of the operation



600
601
602
# File 'lib/dm-core/query/conditions/operation.rb', line 600

def to_s
  empty? ? '' : "NOT(#{operand.to_s})"
end