Class: MongoQL::Stage::Lookup
- Inherits:
-
MongoQL::Stage
- Object
- MongoQL::Stage
- MongoQL::Stage::Lookup
- Defined in:
- lib/mongo_ql/stage/lookup.rb
Defined Under Namespace
Classes: NestedPipelineVars
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#ctx ⇒ Object
Returns the value of attribute ctx.
-
#from ⇒ Object
Returns the value of attribute from.
-
#let_vars ⇒ Object
Returns the value of attribute let_vars.
-
#nested_pipeline ⇒ Object
Returns the value of attribute nested_pipeline.
-
#nested_pipeline_block ⇒ Object
Returns the value of attribute nested_pipeline_block.
Instance Method Summary collapse
-
#initialize(ctx, from, condition = nil, on: nil, as: nil, &block) ⇒ Lookup
constructor
A new instance of Lookup.
- #to_ast ⇒ Object
Constructor Details
#initialize(ctx, from, condition = nil, on: nil, as: nil, &block) ⇒ Lookup
Returns a new instance of Lookup.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongo_ql/stage/lookup.rb', line 38 def initialize(ctx, from, condition = nil, on: nil, as: nil, &block) @ctx = ctx @from = collection_name(from) @as = new_array_name(as) @nested_pipeline_block = block if has_nested_pipeline? @let_vars = NestedPipelineVars.new @nested_pipeline = eval_nested_pipeline else @condition = condition_ast(condition || on) end end |
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def as @as end |
#condition ⇒ Object
Returns the value of attribute condition.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def condition @condition end |
#ctx ⇒ Object
Returns the value of attribute ctx.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def ctx @ctx end |
#from ⇒ Object
Returns the value of attribute from.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def from @from end |
#let_vars ⇒ Object
Returns the value of attribute let_vars.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def let_vars @let_vars end |
#nested_pipeline ⇒ Object
Returns the value of attribute nested_pipeline.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def nested_pipeline @nested_pipeline end |
#nested_pipeline_block ⇒ Object
Returns the value of attribute nested_pipeline_block.
35 36 37 |
# File 'lib/mongo_ql/stage/lookup.rb', line 35 def nested_pipeline_block @nested_pipeline_block end |
Instance Method Details
#to_ast ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mongo_ql/stage/lookup.rb', line 52 def to_ast lookup_expr = { "from" => from, "as" => as } if has_nested_pipeline? lookup_expr["pipeline"] = nested_pipeline lookup_expr["let"] = let_vars.vars else lookup_expr = lookup_expr.merge(condition) end ast = { "$lookup" => lookup_expr } MongoQL::Utils.deep_transform_values(ast, &MongoQL::EXPRESSION_TO_AST_MAPPER) end |