Class: Mongory::Matchers::EveryMatcher
- Inherits:
-
HashConditionMatcher
- Object
- AbstractMatcher
- AbstractMultiMatcher
- HashConditionMatcher
- Mongory::Matchers::EveryMatcher
- Defined in:
- lib/mongory/matchers/every_matcher.rb
Overview
EveryMatcher implements the logic for Mongo-style $every
which is not really support in MongoDB.
It is used to determine if all element in an array matches the given condition.
This matcher delegates element-wise comparison to HashConditionMatcher, allowing nested conditions to be applied recursively.
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.
47 48 49 50 51 |
# File 'lib/mongory/matchers/every_matcher.rb', line 47 def check_validity! raise TypeError, '$every needs a Hash.' unless @condition.is_a?(Hash) super end |
#priority ⇒ Object
39 40 41 |
# File 'lib/mongory/matchers/every_matcher.rb', line 39 def priority 3 + super end |
#raw_proc ⇒ Proc
The proc includes error handling and context-based record conversion
Creates a raw Proc that performs the element matching operation. The Proc checks if all elements in the array match the condition.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongory/matchers/every_matcher.rb', line 23 def raw_proc super_proc = super need_convert = @context.need_convert data_converter = Mongory.data_converter Proc.new do |collection| next false unless collection.is_a?(Array) next false if collection.empty? collection.all? do |record| record = data_converter.convert(record) if need_convert super_proc.call(record) end end end |