module Mongoid::Contextual::Aggregable::None

Contains behavior for aggregating values in null context.

Public Instance Methods

aggregates(_field) click to toggle source

Get all the aggregate values for the provided field in null context. Provided for interface consistency with Aggregable::Mongo.

@param [ String | Symbol ] _field The field name.

@return [ Hash ] A Hash with count, sum of 0 and max, min, avg of nil.

# File lib/mongoid/contextual/aggregable/none.rb, line 18
def aggregates(_field)
  Aggregable::EMPTY_RESULT.dup
end
avg(_field) click to toggle source

Always returns nil.

@example Get the avg of null context.

@param [ Symbol ] _field The field to avg.

@return [ nil ] Always nil.

# File lib/mongoid/contextual/aggregable/none.rb, line 40
def avg(_field)
  nil
end
max(_field = nil)

Always returns nil.

@example Get the max of null context.

@param [ Symbol ] _field The field to max.

@return [ nil ] Always nil.

Alias for: min
min(_field = nil) click to toggle source

Always returns nil.

@example Get the min of null context.

@param [ Symbol ] _field The field to min.

@return [ nil ] Always nil.

# File lib/mongoid/contextual/aggregable/none.rb, line 51
def min(_field = nil)
  nil
end
Also aliased as: max
sum(_field = nil) click to toggle source

Always returns zero.

@example Get the sum of null context.

@param [ Symbol ] _field The field to sum.

@return [ Integer ] Always zero.

# File lib/mongoid/contextual/aggregable/none.rb, line 29
def sum(_field = nil)
  0
end