Class: Mongoid::Contextual::None
- Inherits:
-
Object
- Object
- Mongoid::Contextual::None
- Includes:
- Enumerable, Aggregable::None, Queryable
- Defined in:
- lib/mongoid/contextual/none.rb
Instance Attribute Summary collapse
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Attributes included from Queryable
#collection, #collection The collection to query against., #criteria The criteria for the context., #klass The klass for the criteria.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Check if the context is equal to the other object.
-
#distinct(_field) ⇒ Array
Get the distinct field values in null context.
-
#each ⇒ Enumerator
Iterate over the null context.
-
#exists? ⇒ false
Do any documents exist for the context.
-
#initialize(criteria) ⇒ None
constructor
Create the new null context.
-
#last ⇒ nil
Always returns nil.
-
#length ⇒ Integer
(also: #size)
Always returns zero.
- #new_sum ⇒ Object
- #old_sum ⇒ Object
-
#pluck(*args) ⇒ Array
Pluck the field values in null context.
-
#sum(_field = nil) ⇒ Integer | Symbol
Get the sum in the null context.
Methods included from Queryable
Methods included from Aggregable::None
Constructor Details
#initialize(criteria) ⇒ None
Create the new null context.
104 105 106 |
# File 'lib/mongoid/contextual/none.rb', line 104 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
14 15 16 |
# File 'lib/mongoid/contextual/none.rb', line 14 def criteria @criteria end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
14 15 16 |
# File 'lib/mongoid/contextual/none.rb', line 14 def klass @klass end |
Instance Method Details
#==(other) ⇒ true, false
Check if the context is equal to the other object.
44 45 46 |
# File 'lib/mongoid/contextual/none.rb', line 44 def ==(other) other.is_a?(None) end |
#distinct(_field) ⇒ Array
Get the distinct field values in null context.
56 57 58 |
# File 'lib/mongoid/contextual/none.rb', line 56 def distinct(_field) [] end |
#each ⇒ Enumerator
Iterate over the null context. There are no documents to iterate over in this case.
69 70 71 72 73 74 75 76 |
# File 'lib/mongoid/contextual/none.rb', line 69 def each if block_given? [].each { |doc| yield(doc) } self else to_enum end end |
#exists? ⇒ false
Do any documents exist for the context.
84 |
# File 'lib/mongoid/contextual/none.rb', line 84 def exists?; false; end |
#last ⇒ nil
Always returns nil.
114 |
# File 'lib/mongoid/contextual/none.rb', line 114 def last; nil; end |
#length ⇒ Integer Also known as: size
Always returns zero.
122 123 124 |
# File 'lib/mongoid/contextual/none.rb', line 122 def length Mongoid.broken_aggregables ? 0 : entries.length end |
#new_sum ⇒ Object
16 |
# File 'lib/mongoid/contextual/none.rb', line 16 alias :new_sum :sum |
#old_sum ⇒ Object
9 |
# File 'lib/mongoid/contextual/none.rb', line 9 alias :old_sum :sum |
#pluck(*args) ⇒ Array
Pluck the field values in null context.
94 95 96 |
# File 'lib/mongoid/contextual/none.rb', line 94 def pluck(*args) [] end |
#sum(_field = nil) ⇒ Integer | Symbol
Get the sum in the null context.
28 29 30 31 32 33 34 |
# File 'lib/mongoid/contextual/none.rb', line 28 def sum(_field = nil) if Mongoid.broken_aggregables old_sum(_field) else new_sum(_field) end end |