Class: Mongory::Matchers::ArrayRecordMatcher
- Inherits:
-
AbstractMultiMatcher
- Object
- AbstractMatcher
- AbstractMultiMatcher
- Mongory::Matchers::ArrayRecordMatcher
- Defined in:
- lib/mongory/matchers/array_record_matcher.rb
Overview
ArrayRecordMatcher handles matching against array-type records.
This matcher is used when a field value is an array and needs to be matched
against a condition. It supports both exact array matching and element-wise
comparison through $elemMatch
.
For empty conditions, it returns false (using FALSE_PROC).
Constant Summary
Constants inherited from AbstractMultiMatcher
Mongory::Matchers::AbstractMultiMatcher::FALSE_PROC, Mongory::Matchers::AbstractMultiMatcher::TRUE_PROC
Constants inherited from AbstractMatcher
Mongory::Matchers::AbstractMatcher::KEY_NOT_FOUND
Instance Attribute Summary
Attributes inherited from AbstractMatcher
Instance Method Summary collapse
-
#matchers ⇒ Array<AbstractMatcher>
Builds an array of matchers to evaluate the given condition against an array record.
-
#raw_proc ⇒ Proc
Creates a raw Proc that performs the array matching operation.
Methods inherited from AbstractMultiMatcher
build_or_unwrap, #check_validity!, #priority, #render_tree
Methods inherited from AbstractMatcher
#cached_proc, #check_validity!, #debug_proc, define_matcher, #initialize, #match, #match?, #priority, #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
#matchers ⇒ Array<AbstractMatcher>
Builds an array of matchers to evaluate the given condition against an array record.
This method returns multiple matchers that will be evaluated using :any?
logic:
- An equality matcher for exact array match
- A hash condition matcher if the condition is a hash
- An
$elemMatch
matcher for element-wise comparison
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mongory/matchers/array_record_matcher.rb', line 48 define_instance_cache_method(:matchers) do result = [] result << EqMatcher.build(@condition, context: @context) if @condition.is_a?(Array) result << case @condition when Hash HashConditionMatcher.build(parsed_condition, context: @context) when Regexp ElemMatchMatcher.build({ '$regex' => @condition }, context: @context) else ElemMatchMatcher.build({ '$eq' => @condition }, context: @context) end result.sort_by(&:priority) end |
#raw_proc ⇒ Proc
Creates a raw Proc that performs the array matching operation. The Proc checks if any element in the array matches the condition. For empty conditions, returns FALSE_PROC.
36 37 38 |
# File 'lib/mongory/matchers/array_record_matcher.rb', line 36 def raw_proc combine_procs_with_or(*matchers.map(&:to_proc)) end |