Class: Mongory::Matchers::NotMatcher

Inherits:
LiteralMatcher show all
Defined in:
lib/mongory/matchers/not_matcher.rb

Overview

NotMatcher implements the $not logical operator.

It returns true if the wrapped matcher fails, effectively inverting the result.

It delegates to LiteralMatcher and simply negates the outcome.

This allows constructs like: { age: { :$not => { :$gte => 30 } } }

Examples:

matcher = NotMatcher.build({ :$gte => 10 })
matcher.match?(5)    #=> true
matcher.match?(15)   #=> false

See Also:

Constant Summary

Constants inherited from AbstractMatcher

AbstractMatcher::KEY_NOT_FOUND

Instance Attribute Summary

Attributes inherited from AbstractMatcher

#condition, #context

Instance Method Summary collapse

Methods inherited from LiteralMatcher

#array_record_matcher, #check_validity!, #dispatched_matcher, #render_tree

Methods inherited from AbstractMatcher

#cached_proc, #check_validity!, #debug_proc, define_matcher, #initialize, #match, #match?, #render_tree, #uniq_key

Methods included from Utils

included, included_classes, #is_blank?, #is_present?

Constructor Details

This class inherits a constructor from Mongory::Matchers::AbstractMatcher

Instance Method Details

#raw_procProc

Creates a raw Proc that performs the not-matching operation. The Proc inverts the result of the wrapped matcher.

Returns:

  • (Proc)

    A proc that performs not-matching



25
26
27
28
29
30
31
# File 'lib/mongory/matchers/not_matcher.rb', line 25

def raw_proc
  super_proc = super

  Proc.new do |record|
    !super_proc.call(record)
  end
end