Class: Mongory::Matchers::Registry

Inherits:
Struct
  • Object
show all
Defined in:
lib/mongory/matchers.rb

Overview

Internal helper representing a registration of an operator and its associated symbol snippet method. Used to delay method definition on Symbol until explicitly enabled.

Each instance holds:

  • the method symbol (e.g., :gt)
  • the corresponding Mongo-style operator (e.g., "$gt")

These instances are collected and replayed upon calling Matchers.enable_symbol_snippets!.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#method_symSymbol

Returns the symbol method name (e.g., :in, :gt, :exists).

Returns:

  • (Symbol)

    the symbol method name (e.g., :in, :gt, :exists)



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/mongory/matchers.rb', line 138

Registry = Struct.new(:method_sym, :operator) do
  # Defines a method on Symbol to support operator snippet expansion.
  #
  # @return [void]
  def apply!
    return if Symbol.method_defined?(method_sym)

    operator = operator()
    Symbol.define_method(method_sym) do
      Mongory::QueryOperator.new(to_s, operator)
    end
  end
end

#operatorString

Returns the Mongo-style operator this snippet maps to (e.g., "$in").

Returns:

  • (String)

    the Mongo-style operator this snippet maps to (e.g., "$in")



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/mongory/matchers.rb', line 138

Registry = Struct.new(:method_sym, :operator) do
  # Defines a method on Symbol to support operator snippet expansion.
  #
  # @return [void]
  def apply!
    return if Symbol.method_defined?(method_sym)

    operator = operator()
    Symbol.define_method(method_sym) do
      Mongory::QueryOperator.new(to_s, operator)
    end
  end
end

Instance Method Details

#apply!void

This method returns an undefined value.

Defines a method on Symbol to support operator snippet expansion.



142
143
144
145
146
147
148
149
# File 'lib/mongory/matchers.rb', line 142

def apply!
  return if Symbol.method_defined?(method_sym)

  operator = operator()
  Symbol.define_method(method_sym) do
    Mongory::QueryOperator.new(to_s, operator)
  end
end