Class: Mongory::QueryMatcher
- Inherits:
-
Matchers::HashConditionMatcher
- Object
- Matchers::AbstractMatcher
- Matchers::AbstractMultiMatcher
- Matchers::HashConditionMatcher
- Mongory::QueryMatcher
- Defined in:
- lib/mongory/query_matcher.rb
Overview
The top-level matcher for compiled query conditions.
Delegates to Matchers::LiteralMatcher after transforming input via Converters::ConditionConverter.
Typically used internally by QueryBuilder
.
Conversion via Mongory.data_converter is applied to the record before matching to ensure consistent data types.
Constant Summary
Constants inherited from Matchers::AbstractMultiMatcher
Matchers::AbstractMultiMatcher::FALSE_PROC, Matchers::AbstractMultiMatcher::TRUE_PROC
Constants inherited from Matchers::AbstractMatcher
Matchers::AbstractMatcher::KEY_NOT_FOUND
Instance Attribute Summary
Attributes inherited from Matchers::AbstractMatcher
Instance Method Summary collapse
-
#check_validity! ⇒ void
Overrides the parent class's check_validity! to prevent premature matcher tree construction.
-
#initialize(condition, context: Utils::Context.new) ⇒ QueryMatcher
constructor
Initializes a new query matcher with the given condition.
-
#prepare_query ⇒ void
Prepares the query for execution by ensuring all necessary matchers are initialized.
-
#raw_proc ⇒ Proc
Returns a Proc that can be used for fast matching.
-
#render_tree ⇒ void
Renders the full matcher tree for the current query.
Methods inherited from Matchers::HashConditionMatcher
Methods inherited from Matchers::AbstractMultiMatcher
Methods inherited from Matchers::AbstractMatcher
#cached_proc, #debug_proc, define_matcher, #match, #match?, #priority, #uniq_key
Methods included from Utils
included, included_classes, #is_blank?, #is_present?
Constructor Details
#initialize(condition, context: Utils::Context.new) ⇒ QueryMatcher
Initializes a new query matcher with the given condition. The condition is converted using Mongory.condition_converter before being passed to the parent matcher.
42 43 44 |
# File 'lib/mongory/query_matcher.rb', line 42 def initialize(condition, context: Utils::Context.new) super(Mongory.condition_converter.convert(condition), context: context) end |
Instance Method Details
#check_validity! ⇒ void
This method returns an undefined value.
Overrides the parent class's check_validity! to prevent premature matcher tree construction. This matcher does not require validation, so this is a no-op.
89 90 91 |
# File 'lib/mongory/query_matcher.rb', line 89 def check_validity! # No-op for this matcher end |
#prepare_query ⇒ void
This method returns an undefined value.
Prepares the query for execution by ensuring all necessary matchers are initialized. This is called before query execution to avoid premature matcher tree construction.
83 |
# File 'lib/mongory/query_matcher.rb', line 83 alias_method :prepare_query, :check_validity! |
#raw_proc ⇒ Proc
The proc includes error handling and context-based record conversion
Returns a Proc that can be used for fast matching. The Proc converts the record using Mongory.data_converter and delegates to the superclass's raw_proc.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongory/query_matcher.rb', line 52 def raw_proc super_proc = super need_convert = @context.need_convert data_converter = Mongory.data_converter Proc.new do |record| record = data_converter.convert(record) if need_convert super_proc.call(record) rescue StandardError false end end |
#render_tree ⇒ void
This method returns an undefined value.
Renders the full matcher tree for the current query. This method is intended to be the public entry point for rendering the matcher tree. It does not accept any arguments and internally handles rendering via the configured pretty-print logic.
Subclasses or internal matchers should implement their own
#render_tree(prefix, is_last:)
for internal recursion.
75 76 77 |
# File 'lib/mongory/query_matcher.rb', line 75 def render_tree super end |