123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Contextual::Aggregable::None

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongoid/contextual/aggregable/none.rb

Overview

Contains behavior for aggregating values in null context.

Instance Method Summary

Instance Method Details

#aggregates(_field) ⇒ Hash

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

Parameters:

Returns:

  • (Hash)

    A Hash with count, sum of 0 and max, min, avg of nil.

[ GitHub ]

  
# File 'lib/mongoid/contextual/aggregable/none.rb', line 18

def aggregates(_field)
  Aggregable::EMPTY_RESULT.dup
end

#avg(_field) ⇒ nil

Always returns nil.

Examples:

Get the avg of null context.

Parameters:

  • _field (Symbol)

    The field to avg.

Returns:

  • (nil)

    Always nil.

[ GitHub ]

  
# File 'lib/mongoid/contextual/aggregable/none.rb', line 40

def avg(_field)
  nil
end

#max(_field = nil)

Alias for #min.

[ GitHub ]

  
# File 'lib/mongoid/contextual/aggregable/none.rb', line 62

alias :max :min

#min(_field = nil) ⇒ nil Also known as: #max

Always returns nil.

Examples:

Get the min of null context.

Parameters:

  • _field (Symbol) (defaults to: nil)

    The field to min.

Returns:

  • (nil)

    Always nil.

[ GitHub ]

  
# File 'lib/mongoid/contextual/aggregable/none.rb', line 51

def min(_field = nil)
  nil
end

#sum(_field = nil) ⇒ Integer

Always returns zero.

Examples:

Get the sum of null context.

Parameters:

  • _field (Symbol) (defaults to: nil)

    The field to sum.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/contextual/aggregable/none.rb', line 29

def sum(_field = nil)
  0
end