Module: Mongory::Matchers::Validator
- Defined in:
- lib/mongory/matchers.rb
Overview
Internal helper module used by Matchers.registry
to validate matcher registration parameters.
This includes:
- Ensuring operators are valid Mongo-style strings (e.g., "$gt")
- Verifying matcher class inheritance
- Enforcing naming rules for symbol snippets (e.g., :gt, :not_match)
These validations protect against incorrect matcher setup and prevent unsafe symbol definitions.
Class Method Summary collapse
-
.validate_class(klass) ⇒ void
Validates the matcher class to ensure it is a subclass of AbstractMatcher.
-
.validate_method(method_sym) ⇒ void
Validates the method symbol to ensure it is a valid lowercase underscore symbol (e.g., :gt, :not_match).
-
.validate_operator(operator) ⇒ void
Validates the given operator string.
Class Method Details
.validate_class(klass) ⇒ void
This method returns an undefined value.
Validates the matcher class to ensure it is a subclass of AbstractMatcher.
105 106 107 108 109 |
# File 'lib/mongory/matchers.rb', line 105 def self.validate_class(klass) return if klass.is_a?(Class) && klass < AbstractMatcher raise Mongory::TypeError, "Matcher class must be a subclass of AbstractMatcher, but got #{klass}" end |
.validate_method(method_sym) ⇒ void
This method returns an undefined value.
Validates the method symbol to ensure it is a valid lowercase underscore symbol (e.g., :gt, :not_match).
116 117 118 119 120 |
# File 'lib/mongory/matchers.rb', line 116 def self.validate_method(method_sym) return if method_sym.is_a?(Symbol) && method_sym.match?(/^([a-z]+_)*[a-z]+$/) raise Mongory::TypeError, "Method symbol must match /^([a-z]+_)*[a-z]+$/, but got #{method_sym.inspect}" end |
.validate_operator(operator) ⇒ void
This method returns an undefined value.
Validates the given operator string. Ensures it matches the Mongo-style format like "$gt". Warns on duplicate registration.
90 91 92 93 94 95 96 97 98 |
# File 'lib/mongory/matchers.rb', line 90 def self.validate_operator(operator) if Matchers.lookup(operator) warn "Duplicate operator registration: #{operator} (#{Matchers.lookup(operator)} vs #{klass})" end return if operator.is_a?(String) && operator.match?(/^\$[a-z]+([A-Z][a-z]+)*$/) raise Mongory::TypeError, "Operator must match /^\$[a-z]+([A-Z][a-z]*)*$/, but got #{operator.inspect}" end |