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

Included in:
None
Defined in:
build/mongoid-master/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.



17
18
19
# File 'build/mongoid-master/lib/mongoid/contextual/aggregable/none.rb', line 17

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.



39
40
41
# File 'build/mongoid-master/lib/mongoid/contextual/aggregable/none.rb', line 39

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.



50
51
52
# File 'build/mongoid-master/lib/mongoid/contextual/aggregable/none.rb', line 50

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.



28
29
30
# File 'build/mongoid-master/lib/mongoid/contextual/aggregable/none.rb', line 28

def sum(_field = nil)
  0
end