class DataMapper::Query::Conditions::NotOperation

Public Instance Methods

<<(operand) click to toggle source

Add an operand to the operation

This will only allow a single operand to be added.

@param [AbstractOperation, AbstractComparison, Array] operand

the operand to add

@return [self]

the operation

@api semipublic

# File lib/dm-core/query/conditions/operation.rb, line 560
def <<(operand)
  assert_one_operand(operand)
  assert_no_self_reference(operand)
  super
end
matches?(record) click to toggle source

Match the record

@param [Resource, Hash] record

the resource to match

@return [true]

true if the record matches, false if not

@api semipublic

# File lib/dm-core/query/conditions/operation.rb, line 544
def matches?(record)
  operand = self.operand
  operand.respond_to?(:matches?) ? !operand.matches?(record) : true
end
minimize() click to toggle source

Minimize the operation

@return [self]

the minimized NotOperation

@return [AbstractOperation, AbstractComparison, Array]

the minimized operation

@api semipublic

# File lib/dm-core/query/conditions/operation.rb, line 584
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?() click to toggle source

Test if the operation is negated

Defaults to return false.

@return [Boolean]

true if the operation is negated, false if not

@api private

# File lib/dm-core/query/conditions/operation.rb, line 611
def negated?
  parent = self.parent
  parent ? !parent.negated? : true
end
operand() click to toggle source

Return the only operand in the operation

@return [AbstractOperation, AbstractComparison, Array]

the operand

@api semipublic

# File lib/dm-core/query/conditions/operation.rb, line 572
def operand
  first
end
to_s() click to toggle source

Return the string representation of the operation

@return [String]

the string representation of the operation

@api semipublic

# File lib/dm-core/query/conditions/operation.rb, line 599
def to_s
  empty? ? '' : "NOT(#{operand.to_s})"
end

Private Instance Methods

assert_no_self_reference(operand) click to toggle source

Assert the operand is not equal to self

@param [AbstractOperation, AbstractComparison, Array] operand

the operand to test

@return [undefined]

@raise [ArgumentError]

raised if object is appended to itself

@api private

# File lib/dm-core/query/conditions/operation.rb, line 646
def assert_no_self_reference(operand)
  if equal?(operand)
    raise ArgumentError, 'cannot append operand to itself'
  end
end
assert_one_operand(operand) click to toggle source

Assert there is only one operand

@param [AbstractOperation, AbstractComparison, Array] operand

the operand to test

@return [undefined]

@raise [ArgumentError]

raised if the operand is not a valid type

@api private

# File lib/dm-core/query/conditions/operation.rb, line 629
def assert_one_operand(operand)
  unless empty? || self.operand == operand
    raise ArgumentError, "#{self.class} cannot have more than one operand"
  end
end