Class: MongoQL::Expression

Inherits:
Object
  • Object
show all
Includes:
BinaryOperators, CollectionOperators, StringOperators, UnaryOperators
Defined in:
lib/mongo_ql/expression.rb

Defined Under Namespace

Classes: Ascend, Binary, Condition, DateNode, Descend, FieldNode, MethodCall, Projection, Unary, ValueNode

Constant Summary collapse

FORMATING_OPS =
{
  "to_object_id": "$toObjectId",
  "to_id":        "$toObjectId",
  "to_s":         "$toString",
  "to_string":    "$toString",
  "to_int":       "$toInt",
  "to_long":      "$toLong",
  "to_bool":      "$toBool",
  "to_date":      "$toDate",
  "to_decimal":   "$toDecimal",
  "to_double":    "$toDouble",
  "downcase":     "$toLower",
  "to_lower":     "$toLower",
  "upcase":       "$toUpper",
  "to_upper":     "$toUpper"
}.freeze

Constants included from CollectionOperators

CollectionOperators::AGGREGATE_OPS

Constants included from UnaryOperators

UnaryOperators::UNARY_OPS

Constants included from BinaryOperators

BinaryOperators::BINARY_OPS

Instance Method Summary collapse

Methods included from StringOperators

#concat, #substr, #trim

Methods included from CollectionOperators

#any?, #concat_arrays, #contains, #filter, #map, #reduce

Instance Method Details

#as_dateObject



51
52
53
# File 'lib/mongo_ql/expression.rb', line 51

def as_date
  Expression::DateNode.new(self)
end

#if_null(default_val) ⇒ Object Also known as: default



44
45
46
47
48
# File 'lib/mongo_ql/expression.rb', line 44

def if_null(default_val)
  Expression::MethodCall.new "$ifNull", self, ast_template: -> (target, **_args) {
    [target, to_expression(default_val)]
  }
end

#then(then_expr = nil, &block) ⇒ Object



55
56
57
# File 'lib/mongo_ql/expression.rb', line 55

def then(then_expr = nil, &block)
  Expression::Condition.new(self, then_expr, nil, &block)
end

#to_astObject

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/mongo_ql/expression.rb', line 59

def to_ast
  raise NotImplementedError, "#{self.class.name} must implement to_ast"
end

#typeObject



40
41
42
# File 'lib/mongo_ql/expression.rb', line 40

def type
  Expression::MethodCall.new "$type", self
end