Class: MongoQL::Stage::Unwind

Inherits:
MongoQL::Stage show all
Defined in:
lib/mongo_ql/stage/unwind.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, path, allow_null: false) ⇒ Unwind

Returns a new instance of Unwind.



7
8
9
10
11
# File 'lib/mongo_ql/stage/unwind.rb', line 7

def initialize(ctx, path, allow_null: false)
  @ctx        = ctx
  @path       = to_expression(path)
  @allow_null = allow_null
end

Instance Attribute Details

#allow_nullObject

Returns the value of attribute allow_null.



5
6
7
# File 'lib/mongo_ql/stage/unwind.rb', line 5

def allow_null
  @allow_null
end

#ctxObject

Returns the value of attribute ctx.



5
6
7
# File 'lib/mongo_ql/stage/unwind.rb', line 5

def ctx
  @ctx
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/mongo_ql/stage/unwind.rb', line 5

def path
  @path
end

Instance Method Details

#to_astObject



13
14
15
16
17
18
19
20
21
# File 'lib/mongo_ql/stage/unwind.rb', line 13

def to_ast
  ast = {
    "$unwind" => {
      "path" => path,
      "preserveNullAndEmptyArrays" => allow_null
    }
  }
  MongoQL::Utils.deep_transform_values(ast, &MongoQL::EXPRESSION_TO_AST_MAPPER)
end