class MongoQL::Expression::Condition

Attributes

condition[RW]
else_expr[RW]
then_expr[RW]

Public Class Methods

new(condition, then_val = nil, else_val = nil) { || ... } click to toggle source
# File lib/mongo_ql/expression/condition.rb, line 7
def initialize(condition, then_val = nil, else_val = nil, &block)
  @condition = condition
  @then_expr = then_val
  @else_expr = else_val

  @then_expr = yield if block_given?
end

Public Instance Methods

Else(else_val = nil, &block)
Alias for: else
Then(then_val = nil, &block)
Alias for: then
else(else_val = nil) { || ... } click to toggle source
# File lib/mongo_ql/expression/condition.rb, line 22
def else(else_val = nil, &block)
  @else_expr = else_val
  @else_expr = yield if block_given?
  self
end
Also aliased as: Else
then(then_val = nil) { || ... } click to toggle source
# File lib/mongo_ql/expression/condition.rb, line 15
def then(then_val = nil, &block)
  @then_expr = then_val
  @then_expr = yield if block_given?
  self
end
Also aliased as: Then
to_ast() click to toggle source
# File lib/mongo_ql/expression/condition.rb, line 29
def to_ast
  {
    "$cond" => [condition, then_expr, else_expr]
  }
end