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

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

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:

  • the operand to add

Returns:

  • the operation

API:

  • semipublic



554
555
556
557
558
# File 'lib/dm-core/query/conditions/operation.rb', line 554

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

#matches?(record) ⇒ true

Match the record

Parameters:

  • the resource to match

Returns:

  • true if the record matches, false if not

API:

  • semipublic



538
539
540
541
# File 'lib/dm-core/query/conditions/operation.rb', line 538

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

#minimizeself, ...

Minimize the operation

Returns:

  • the minimized NotOperation

  • the minimized operation

API:

  • semipublic



578
579
580
581
582
583
584
585
# File 'lib/dm-core/query/conditions/operation.rb', line 578

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:

  • true if the operation is negated, false if not

API:

  • private



605
606
607
608
# File 'lib/dm-core/query/conditions/operation.rb', line 605

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

#operandAbstractOperation, ...

Return the only operand in the operation

Returns:

  • the operand

API:

  • semipublic



566
567
568
# File 'lib/dm-core/query/conditions/operation.rb', line 566

def operand
  first
end

#to_sString

Return the string representation of the operation

Returns:

  • the string representation of the operation

API:

  • semipublic



593
594
595
# File 'lib/dm-core/query/conditions/operation.rb', line 593

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