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

Included in:
None
Defined in:
lib/mongoid/contextual/aggregable/none.rb

Overview

Contains behavior for aggregating values in null context.

Instance Method Summary collapse

Instance Method Details

#aggregates(_field) ⇒ Hash

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

Parameters:

  • _field (String | Symbol)

    The field name.

Returns:

  • (Hash)

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



18
19
20
# 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.



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

def avg(_field)
  nil
end

#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.



51
52
53
# 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:

  • (Integer)

    Always zero.



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

def sum(_field = nil)
  0
end