Class: Mongory::Matchers::EqMatcher

Inherits:
AbstractMatcher show all
Defined in:
lib/mongory/matchers/eq_matcher.rb

Overview

Note:

This matcher is also used as the fallback for non-operator literal values, such as { name: "Alice" }, when no other specialized matcher is applicable.

Note:

Equality behavior depends on how == is implemented for the given objects.

EqMatcher matches values using the equality operator ==.

It inherits from AbstractMatcher and defines its operator as :==.

Used for conditions like:

  • { age: { '$eq' => 30 } }
  • { name: "Alice" } (implicit fallback)

This matcher supports any Ruby object that implements #==.

Examples:

matcher = EqMatcher.build(42)
matcher.match?(42)       #=> true
matcher.match?("42")     #=> 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 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

#priorityObject



39
40
41
# File 'lib/mongory/matchers/eq_matcher.rb', line 39

def priority
  1
end

#raw_procProc

Creates a raw Proc that performs the equality check. The Proc uses the == operator to compare values.

Returns:

  • (Proc)

    a Proc that performs the equality check



31
32
33
34
35
36
37
# File 'lib/mongory/matchers/eq_matcher.rb', line 31

def raw_proc
  condition = @condition

  Proc.new do |record|
    record == condition
  end
end