Class: Mongory::QueryOperator

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

Overview

Wrapper for symbol-based operator expressions.

Used to support DSL like :age.gt => 18 where gt maps to $gt. Converts into: { "age" => { "$gt" => 18 } }

Instance Method Summary collapse

Constructor Details

#initialize(name, operator) ⇒ QueryOperator

Initializes a new query operator wrapper.

Parameters:

  • name (String)

    the original field name

  • operator (String)

    the Mongo-style operator (e.g., '$gt')



13
14
15
16
# File 'lib/mongory/query_operator.rb', line 13

def initialize(name, operator)
  @name = name
  @operator = operator
end

Instance Method Details

#__expr_part__(other) ⇒ Hash

Converts the operator and value into a condition hash.

Typically called by the key converter.

Parameters:

  • other (Object)

    the value to match against

Returns:

  • (Hash)

    converted query condition



24
25
26
# File 'lib/mongory/query_operator.rb', line 24

def __expr_part__(other, *)
  { @name => { @operator => other } }
end