Class: Mongory::Matchers::ElemMatchMatcher
- Inherits:
-
HashConditionMatcher
- Object
- AbstractMatcher
- AbstractMultiMatcher
- HashConditionMatcher
- Mongory::Matchers::ElemMatchMatcher
- Defined in:
- lib/mongory/matchers/elem_match_matcher.rb
Overview
ElemMatchMatcher implements the logic for Mongo-style $elemMatch
.
It is used to determine if any element in an array matches the given condition.
This matcher delegates element-wise comparison to HashConditionMatcher, allowing nested conditions to be applied recursively.
Typically used internally by ArrayRecordMatcher when dealing with non-indexed hash-style subconditions.
Constant Summary
Constants inherited from AbstractMultiMatcher
AbstractMultiMatcher::FALSE_PROC, AbstractMultiMatcher::TRUE_PROC
Constants inherited from AbstractMatcher
AbstractMatcher::KEY_NOT_FOUND
Instance Attribute Summary
Attributes inherited from AbstractMatcher
Instance Method Summary collapse
-
#check_validity! ⇒ void
Ensures the condition is a Hash.
- #priority ⇒ Object
-
#raw_proc ⇒ Proc
Creates a raw Proc that performs the element matching operation.
Methods inherited from HashConditionMatcher
Methods inherited from AbstractMultiMatcher
Methods inherited from AbstractMatcher
#cached_proc, #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
#check_validity! ⇒ void
This method returns an undefined value.
Ensures the condition is a Hash.
46 47 48 49 50 |
# File 'lib/mongory/matchers/elem_match_matcher.rb', line 46 def check_validity! raise TypeError, '$elemMatch needs a Hash.' unless @condition.is_a?(Hash) super end |
#priority ⇒ Object
38 39 40 |
# File 'lib/mongory/matchers/elem_match_matcher.rb', line 38 def priority 3 + super end |
#raw_proc ⇒ Proc
Creates a raw Proc that performs the element matching operation. The Proc checks if any element in the array matches the condition.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongory/matchers/elem_match_matcher.rb', line 25 def raw_proc super_proc = super need_convert = @context.need_convert data_converter = Mongory.data_converter Proc.new do |collection| collection.any? do |record| record = data_converter.convert(record) if need_convert super_proc.call(record) end end end |