Class: Mongory::Matchers::OrMatcher
- Inherits:
-
AbstractMultiMatcher
- Object
- AbstractMatcher
- AbstractMultiMatcher
- Mongory::Matchers::OrMatcher
- Defined in:
- lib/mongory/matchers/or_matcher.rb
Overview
OrMatcher implements the $or
logical operator.
It evaluates an array of subconditions and returns true if any one of them matches. For empty conditions, it returns false (using FALSE_PROC).
Each subcondition is handled by a HashConditionMatcher with conversion disabled, since the parent matcher already manages data conversion.
This matcher inherits submatcher dispatch and evaluation logic from AbstractMultiMatcher.
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 an array of hashes.
-
#matchers ⇒ Array<AbstractMatcher>
Builds an array of matchers from the subconditions.
-
#raw_proc ⇒ Proc
Creates a raw Proc that performs the or-matching operation.
Methods inherited from AbstractMultiMatcher
build_or_unwrap, #priority, #render_tree
Methods inherited from AbstractMatcher
#cached_proc, #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
#check_validity! ⇒ void
This method returns an undefined value.
Ensures the condition is an array of hashes.
55 56 57 58 59 60 61 62 63 |
# File 'lib/mongory/matchers/or_matcher.rb', line 55 def check_validity! raise TypeError, '$or needs an array' unless @condition.is_a?(Array) @condition.each do |sub_condition| raise TypeError, '$or needs an array of hash' unless sub_condition.is_a?(Hash) end super end |
#matchers ⇒ Array<AbstractMatcher>
Builds an array of matchers from the subconditions. Each subcondition is wrapped in a HashConditionMatcher.
45 46 47 48 49 |
# File 'lib/mongory/matchers/or_matcher.rb', line 45 define_instance_cache_method(:matchers) do @condition.map do |condition| HashConditionMatcher.build(condition, context: @context) end.sort_by(&:priority) end |
#raw_proc ⇒ Proc
Creates a raw Proc that performs the or-matching operation. The Proc combines all submatcher Procs and returns true if any match. For empty conditions, returns FALSE_PROC.
37 38 39 |
# File 'lib/mongory/matchers/or_matcher.rb', line 37 def raw_proc combine_procs_with_or(*matchers.map(&:to_proc)) end |