Class: Casino::Projection
- Inherits:
-
Object
- Object
- Casino::Projection
- Defined in:
- lib/casino/projection.rb
Instance Attribute Summary collapse
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #group(conditions) ⇒ Object (also: #pivot)
-
#initialize(klass, pipeline = []) ⇒ Projection
constructor
A new instance of Projection.
- #limit(conditions) ⇒ Object
- #match(conditions) ⇒ Object (also: #where, #find)
- #mongoize(hash) ⇒ Object
- #project(conditions) ⇒ Object (also: #describe, #build)
- #results ⇒ Object
- #skip(conditions) ⇒ Object (also: #offset)
- #sort(conditions) ⇒ Object (also: #order)
- #unwind(conditions) ⇒ Object (also: #expand)
Constructor Details
#initialize(klass, pipeline = []) ⇒ Projection
Returns a new instance of Projection.
5 6 7 8 |
# File 'lib/casino/projection.rb', line 5 def initialize(klass, pipeline = []) self.target = klass self.pipeline = pipeline end |
Instance Attribute Details
#pipeline ⇒ Object
Returns the value of attribute pipeline.
3 4 5 |
# File 'lib/casino/projection.rb', line 3 def pipeline @pipeline end |
#target ⇒ Object
Returns the value of attribute target.
3 4 5 |
# File 'lib/casino/projection.rb', line 3 def target @target end |
Instance Method Details
#group(conditions) ⇒ Object Also known as: pivot
18 19 20 |
# File 'lib/casino/projection.rb', line 18 def group(conditions) clone_with group: conditions end |
#limit(conditions) ⇒ Object
50 51 52 |
# File 'lib/casino/projection.rb', line 50 def limit(conditions) clone_with limit: conditions end |
#match(conditions) ⇒ Object Also known as: where, find
34 35 36 |
# File 'lib/casino/projection.rb', line 34 def match(conditions) clone_with match: conditions end |
#mongoize(hash) ⇒ Object
14 15 16 |
# File 'lib/casino/projection.rb', line 14 def mongoize(hash) hash.keys.map { |key| build_mongoized_hash(hash, key) }.reduce(&:merge) end |
#project(conditions) ⇒ Object Also known as: describe, build
23 24 25 |
# File 'lib/casino/projection.rb', line 23 def project(conditions) clone_with project: conditions end |
#results ⇒ Object
10 11 12 |
# File 'lib/casino/projection.rb', line 10 def results target.collection.aggregate(pipeline) end |
#skip(conditions) ⇒ Object Also known as: offset
45 46 47 |
# File 'lib/casino/projection.rb', line 45 def skip(conditions) clone_with skip: conditions end |
#sort(conditions) ⇒ Object Also known as: order
40 41 42 |
# File 'lib/casino/projection.rb', line 40 def sort(conditions) clone_with sort: conditions end |
#unwind(conditions) ⇒ Object Also known as: expand
29 30 31 |
# File 'lib/casino/projection.rb', line 29 def unwind(conditions) clone_with unwind: conditions end |