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?(id_or_conditions = :none) ⇒ false
Do any documents exist for the context.
-
#fifth ⇒ nil
Always returns nil.
-
#fifth! ⇒ Object
Always raises an error.
-
#first(limit = nil) ⇒ [] | nil
(also: #find_first, #one)
Always returns nil.
-
#first! ⇒ Object
Always raises an error.
-
#fourth ⇒ nil
Always returns nil.
-
#fourth! ⇒ Object
Always raises an error.
-
#initialize(criteria) ⇒ None
constructor
Create the new null context.
-
#last(limit = nil) ⇒ [] | nil
Always returns nil.
-
#last! ⇒ Object
Always raises an error.
-
#length ⇒ Integer
(also: #size)
Always returns zero.
- #new_sum ⇒ Object
- #old_sum ⇒ Object
-
#pick(*_fields) ⇒ nil
Pick the field values in null context.
-
#pluck(*_fields) ⇒ Array
Pluck the field values in null context.
-
#second ⇒ nil
Always returns nil.
-
#second! ⇒ Object
Always raises an error.
-
#second_to_last ⇒ nil
Always returns nil.
-
#second_to_last! ⇒ Object
Always raises an error.
-
#sum(_field = nil) ⇒ Integer | Symbol
Get the sum in the null context.
-
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
-
#take! ⇒ Object
Always raises an error.
-
#tally(_field) ⇒ Hash
Tally the field values in null context.
-
#third ⇒ nil
Always returns nil.
-
#third! ⇒ Object
Always raises an error.
-
#third_to_last ⇒ nil
Always returns nil.
-
#third_to_last! ⇒ Object
Always raises an error.
Methods included from Queryable
Methods included from Aggregable::None
Constructor Details
#initialize(criteria) ⇒ None
Create the new null context.
137 138 139 |
# File 'lib/mongoid/contextual/none.rb', line 137 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?(id_or_conditions = :none) ⇒ false
Do any documents exist for the context.
93 |
# File 'lib/mongoid/contextual/none.rb', line 93 def exists?(id_or_conditions = :none); false; end |
#fifth ⇒ nil
Always returns nil.
273 274 275 |
# File 'lib/mongoid/contextual/none.rb', line 273 def fifth nil end |
#fifth! ⇒ Object
Always raises an error.
283 284 285 |
# File 'lib/mongoid/contextual/none.rb', line 283 def fifth! raise_document_not_found_error end |
#first(limit = nil) ⇒ [] | nil Also known as: find_first, one
Always returns nil.
149 150 151 |
# File 'lib/mongoid/contextual/none.rb', line 149 def first(limit = nil) [] unless limit.nil? end |
#first! ⇒ Object
Always raises an error.
159 160 161 |
# File 'lib/mongoid/contextual/none.rb', line 159 def first! raise_document_not_found_error end |
#fourth ⇒ nil
Always returns nil.
253 254 255 |
# File 'lib/mongoid/contextual/none.rb', line 253 def fourth nil end |
#fourth! ⇒ Object
Always raises an error.
263 264 265 |
# File 'lib/mongoid/contextual/none.rb', line 263 def fourth! raise_document_not_found_error end |
#last(limit = nil) ⇒ [] | nil
Always returns nil.
171 172 173 |
# File 'lib/mongoid/contextual/none.rb', line 171 def last(limit = nil) [] unless limit.nil? end |
#last! ⇒ Object
Always raises an error.
181 182 183 |
# File 'lib/mongoid/contextual/none.rb', line 181 def last! raise_document_not_found_error end |
#length ⇒ Integer Also known as: size
Always returns zero.
333 334 335 |
# File 'lib/mongoid/contextual/none.rb', line 333 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 |
#pick(*_fields) ⇒ nil
Pick the field values in null context.
115 116 117 |
# File 'lib/mongoid/contextual/none.rb', line 115 def pick(*_fields) nil end |
#pluck(*_fields) ⇒ Array
Pluck the field values in null context.
103 104 105 |
# File 'lib/mongoid/contextual/none.rb', line 103 def pluck(*_fields) [] end |
#second ⇒ nil
Always returns nil.
213 214 215 |
# File 'lib/mongoid/contextual/none.rb', line 213 def second nil end |
#second! ⇒ Object
Always raises an error.
223 224 225 |
# File 'lib/mongoid/contextual/none.rb', line 223 def second! raise_document_not_found_error end |
#second_to_last ⇒ nil
Always returns nil.
293 294 295 |
# File 'lib/mongoid/contextual/none.rb', line 293 def second_to_last nil end |
#second_to_last! ⇒ Object
Always raises an error.
303 304 305 |
# File 'lib/mongoid/contextual/none.rb', line 303 def second_to_last! raise_document_not_found_error 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 |
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
193 194 195 |
# File 'lib/mongoid/contextual/none.rb', line 193 def take(limit = nil) limit ? [] : nil end |
#take! ⇒ Object
Always raises an error.
203 204 205 |
# File 'lib/mongoid/contextual/none.rb', line 203 def take! raise_document_not_found_error end |
#tally(_field) ⇒ Hash
Tally the field values in null context.
127 128 129 |
# File 'lib/mongoid/contextual/none.rb', line 127 def tally(_field) {} end |
#third ⇒ nil
Always returns nil.
233 234 235 |
# File 'lib/mongoid/contextual/none.rb', line 233 def third nil end |
#third! ⇒ Object
Always raises an error.
243 244 245 |
# File 'lib/mongoid/contextual/none.rb', line 243 def third! raise_document_not_found_error end |
#third_to_last ⇒ nil
Always returns nil.
313 314 315 |
# File 'lib/mongoid/contextual/none.rb', line 313 def third_to_last nil end |
#third_to_last! ⇒ Object
Always raises an error.
323 324 325 |
# File 'lib/mongoid/contextual/none.rb', line 323 def third_to_last! raise_document_not_found_error end |