class DataMapper::Query::Conditions::NotOperation
Public Instance Methods
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
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 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
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
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
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 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 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