Module: Mongory::Matchers
- Defined in:
- lib/mongory/matchers.rb,
lib/mongory/matchers/eq_matcher.rb,
lib/mongory/matchers/gt_matcher.rb,
lib/mongory/matchers/in_matcher.rb,
lib/mongory/matchers/lt_matcher.rb,
lib/mongory/matchers/ne_matcher.rb,
lib/mongory/matchers/or_matcher.rb,
lib/mongory/matchers/and_matcher.rb,
lib/mongory/matchers/gte_matcher.rb,
lib/mongory/matchers/lte_matcher.rb,
lib/mongory/matchers/nin_matcher.rb,
lib/mongory/matchers/not_matcher.rb,
lib/mongory/matchers/size_matcher.rb,
lib/mongory/matchers/every_matcher.rb,
lib/mongory/matchers/field_matcher.rb,
lib/mongory/matchers/regex_matcher.rb,
lib/mongory/matchers/exists_matcher.rb,
lib/mongory/matchers/literal_matcher.rb,
lib/mongory/matchers/present_matcher.rb,
lib/mongory/matchers/abstract_matcher.rb,
lib/mongory/matchers/elem_match_matcher.rb,
lib/mongory/matchers/array_record_matcher.rb,
lib/mongory/matchers/abstract_multi_matcher.rb,
lib/mongory/matchers/hash_condition_matcher.rb
Overview
Provides matcher registration and operator-to-class lookup for query evaluation.
This module is responsible for:
- Mapping Mongo-style operators like "$gt" to matcher classes
- Dynamically extending Symbol with query operator snippets (e.g., :age.gt)
- Safely isolating symbol extension behind an explicit opt-in flag
Matchers are registered using Matchers.registry(method_sym, operator, klass)
and can be looked up via Matchers.lookup(operator)
.
Symbol snippets are only enabled if Matchers.enable_symbol_snippets!
is called,
preventing namespace pollution unless explicitly requested.
Defined Under Namespace
Modules: Validator Classes: AbstractMatcher, AbstractMultiMatcher, AndMatcher, ArrayRecordMatcher, ElemMatchMatcher, EqMatcher, EveryMatcher, ExistsMatcher, FieldMatcher, GtMatcher, GteMatcher, HashConditionMatcher, InMatcher, LiteralMatcher, LtMatcher, LteMatcher, NeMatcher, NinMatcher, NotMatcher, OrMatcher, PresentMatcher, RegexMatcher, Registry, SizeMatcher
Class Method Summary collapse
-
.enable_symbol_snippets! ⇒ void
Enables dynamic symbol snippet generation for registered operators.
- .freeze ⇒ Object
-
.lookup(operator) ⇒ Class?
Retrieves the matcher class associated with a Mongo-style operator.
-
.operators ⇒ Array<String>
Returns all registered operator keys.
-
.register(method_sym, operator, klass) ⇒ void
Registers a matcher class for a given operator and method symbol.
Class Method Details
.enable_symbol_snippets! ⇒ void
This method returns an undefined value.
Enables dynamic symbol snippet generation for registered operators.
This defines methods like :age.gt => QueryOperator.new(...)
.
44 45 46 47 |
# File 'lib/mongory/matchers.rb', line 44 def self.enable_symbol_snippets! @enable_symbol_snippets = true @registries.each(&:apply!) end |
.freeze ⇒ Object
64 65 66 67 68 |
# File 'lib/mongory/matchers.rb', line 64 def self.freeze super @operator_mapping.freeze @registries.freeze end |
.lookup(operator) ⇒ Class?
Retrieves the matcher class associated with a Mongo-style operator.
53 54 55 |
# File 'lib/mongory/matchers.rb', line 53 def self.lookup(operator) @operator_mapping[operator] end |
.operators ⇒ Array<String>
Returns all registered operator keys.
60 61 62 |
# File 'lib/mongory/matchers.rb', line 60 def self.operators @operator_mapping.keys end |
.register(method_sym, operator, klass) ⇒ void
This method returns an undefined value.
Registers a matcher class for a given operator and method symbol.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongory/matchers.rb', line 27 def self.register(method_sym, operator, klass) Validator.validate_method(method_sym) Validator.validate_operator(operator) Validator.validate_class(klass) @operator_mapping[operator] = klass registry = Registry.new(method_sym, operator) @registries << registry return unless @enable_symbol_snippets registry.apply! end |