Module: Origin::Aggregable

Extended by:
Macroable
Included in:
Queryable
Defined in:
lib/origin/aggregable.rb

Overview

Provides a DSL around crafting aggregation framework commands.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Macroable

key

Instance Attribute Details

#aggregating Flag for whether or not we are aggregating.(Flag) ⇒ Object


14
# File 'lib/origin/aggregable.rb', line 14

attr_writer :aggregating

#aggregating=(value) ⇒ Object (writeonly)

Since:

  • 2.0.0


14
15
16
# File 'lib/origin/aggregable.rb', line 14

def aggregating=(value)
  @aggregating = value
end

#pipelineObject (readonly)

Since:

  • 2.0.0


11
12
13
# File 'lib/origin/aggregable.rb', line 11

def pipeline
  @pipeline
end

#pipeline The aggregation pipeline.(Theaggregationpipeline.) ⇒ Object (readonly)


11
# File 'lib/origin/aggregable.rb', line 11

attr_reader :pipeline

Instance Method Details

#aggregating?true, false

Has the aggregable enter an aggregation state. Ie, are only aggregation operations allowed at this point on.

Examples:

Is the aggregable aggregating?

aggregable.aggregating?

Since:

  • 2.0.0


25
26
27
# File 'lib/origin/aggregable.rb', line 25

def aggregating?
  !!@aggregating
end

#group(operation) ⇒ Aggregable

Add a group ($group) operation to the aggregation pipeline.

Examples:

Add a group operation being verbose.

aggregable.group(count: { "$sum" => 1 }, max: { "$max" => "likes" })

Add a group operation using symbol shortcuts.

aggregable.group(:count.sum => 1, :max.max => "likes")

Since:

  • 2.0.0


42
43
44
45
46
# File 'lib/origin/aggregable.rb', line 42

def group(operation)
  aggregation(operation) do |pipeline|
    pipeline.group(operation)
  end
end

#project(operation = nil) ⇒ Aggregable

Add a projection ($project) to the aggregation pipeline.

Examples:

Add a projection to the pipeline.

aggregable.project(author: 1, name: 0)

Since:

  • 2.0.0


66
67
68
69
70
# File 'lib/origin/aggregable.rb', line 66

def project(operation = nil)
  aggregation(operation) do |pipeline|
    pipeline.project(operation)
  end
end

#unwind(field) ⇒ Aggregable

Add an unwind ($unwind) to the aggregation pipeline.

Examples:

Add an unwind to the pipeline.

aggregable.unwind(:field)

Since:

  • 2.0.0


82
83
84
85
86
# File 'lib/origin/aggregable.rb', line 82

def unwind(field)
  aggregation(field) do |pipeline|
    pipeline.unwind(field)
  end
end