Class: Origin::Pipeline
- Inherits:
-
Array
- Object
- Array
- Origin::Pipeline
- Defined in:
- lib/origin/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) ⇒ Pipeline
Add the $unwind entry to the pipeline.
Constructor Details
#initialize(aliases = {}) {|_self| ... } ⇒ Pipeline
Initialize the new pipeline.
52 53 54 55 |
# File 'lib/origin/pipeline.rb', line 52 def initialize(aliases = {}) @aliases = aliases yield(self) if block_given? end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
10 11 12 |
# File 'lib/origin/pipeline.rb', line 10 def aliases @aliases end |
#aliases The field aliases.(Thefieldaliases.) ⇒ Object (readonly)
10 |
# File 'lib/origin/pipeline.rb', line 10 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.
21 22 23 24 25 26 27 |
# File 'lib/origin/pipeline.rb', line 21 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.
39 40 41 |
# File 'lib/origin/pipeline.rb', line 39 def group(entry) push("$group" => evolve(entry.)) end |
#project(entry) ⇒ Pipeline
Adds a $project entry to the aggregation pipeline.
65 66 67 |
# File 'lib/origin/pipeline.rb', line 65 def project(entry) push("$project" => evolve(entry)) end |
#unwind(field) ⇒ Pipeline
Add the $unwind entry to the pipeline.
79 80 81 82 83 |
# File 'lib/origin/pipeline.rb', line 79 def unwind(field) normalized = field.to_s name = aliases[normalized] || normalized push("$unwind" => name.__mongo_expression__) end |