Class: MongoQL::Stage::AddFields
- Inherits:
-
MongoQL::Stage
- Object
- MongoQL::Stage
- MongoQL::Stage::AddFields
- Defined in:
- lib/mongo_ql/stage/add_fields.rb
Instance Attribute Summary collapse
-
#ctx ⇒ Object
Returns the value of attribute ctx.
-
#field_projections ⇒ Object
Returns the value of attribute field_projections.
Instance Method Summary collapse
-
#initialize(ctx, *fields) ⇒ AddFields
constructor
A new instance of AddFields.
- #to_ast ⇒ Object
Constructor Details
#initialize(ctx, *fields) ⇒ AddFields
Returns a new instance of AddFields.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mongo_ql/stage/add_fields.rb', line 8 def initialize(ctx, *fields) @ctx = ctx @field_projections = fields.map do |field| case field when Hash field.map { |k, v| [k.to_s, to_expression(v)] }.to_h else raise ArgumentError, "#{field} is not a valid field mapping option" end end.inject({}) { |p, c| p.merge(c) } end |
Instance Attribute Details
#ctx ⇒ Object
Returns the value of attribute ctx.
5 6 7 |
# File 'lib/mongo_ql/stage/add_fields.rb', line 5 def ctx @ctx end |
#field_projections ⇒ Object
Returns the value of attribute field_projections.
6 7 8 |
# File 'lib/mongo_ql/stage/add_fields.rb', line 6 def field_projections @field_projections end |
Instance Method Details
#to_ast ⇒ Object
20 21 22 23 |
# File 'lib/mongo_ql/stage/add_fields.rb', line 20 def to_ast ast = { "$addFields" => field_projections } MongoQL::Utils.deep_transform_values(ast, &MongoQL::EXPRESSION_TO_AST_MAPPER) end |