Class: Mongoid::Criteria::Queryable::Pipeline
- Inherits:
-
Array
- Object
- Array
- Mongoid::Criteria::Queryable::Pipeline
- Defined in:
- lib/mongoid/criteria/queryable/pipeline.rb
Overview
Represents an aggregation pipeline.
Instance Attribute Summary collapse
- #aliases ⇒ Object readonly
- #aliases The field aliases.(Thefieldaliases.) ⇒ Object readonly
Instance Method Summary collapse
-
#__deep_copy__ ⇒ Pipeline
Deep copy the aggregation pipeline.
-
#group(entry) ⇒ Pipeline
Add a group operation to the aggregation pipeline.
-
#initialize(aliases = {}) {|_self| ... } ⇒ Pipeline
constructor
Initialize the new pipeline.
-
#project(entry) ⇒ Pipeline
Adds a $project entry to the aggregation pipeline.
-
#unwind(field_or_doc) ⇒ Pipeline
Add the $unwind entry to the pipeline.
Constructor Details
#initialize(aliases = {}) {|_self| ... } ⇒ Pipeline
Initialize the new pipeline.
54 55 56 57 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 54 def initialize(aliases = {}) @aliases = aliases yield(self) if block_given? end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
12 13 14 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 12 def aliases @aliases end |
#aliases The field aliases.(Thefieldaliases.) ⇒ Object (readonly)
12 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 12 attr_reader :aliases |
Instance Method Details
#__deep_copy__ ⇒ Pipeline
Deep copy the aggregation pipeline. Will clone all the values in the pipeline as well as the pipeline itself.
23 24 25 26 27 28 29 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 23 def __deep_copy__ self.class.new(aliases) do |copy| each do |entry| copy.push(entry.__deep_copy__) end end end |
#group(entry) ⇒ Pipeline
Add a group operation to the aggregation pipeline.
41 42 43 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 41 def group(entry) push("$group" => evolve(entry.)) end |
#project(entry) ⇒ Pipeline
Adds a $project entry to the aggregation pipeline.
67 68 69 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 67 def project(entry) push("$project" => evolve(entry)) end |
#unwind(field_or_doc) ⇒ Pipeline
Add the $unwind entry to the pipeline.
82 83 84 85 86 87 88 89 90 |
# File 'lib/mongoid/criteria/queryable/pipeline.rb', line 82 def unwind(field_or_doc) unless field_or_doc.respond_to? :keys normalized = field_or_doc.to_s name = aliases[normalized] || normalized push("$unwind" => name.__mongo_expression__) else push("$unwind" => field_or_doc) end end |