Class: Mongoid::Contextual::None
- Inherits:
-
Object
- Object
- Mongoid::Contextual::None
- Includes:
- Enumerable, Aggregable::None, Queryable
- Defined in:
- lib/mongoid/contextual/none.rb
Overview
Context object used for performing bulk query and persistence operations on a null set. The method interface of this class is consistent with Mongoid::Contextual::Mongo.
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.
-
#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.
-
#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
#aggregates, #avg, #min, #sum
Constructor Details
#initialize(criteria) ⇒ None
Create the new null context.
120 121 122 |
# File 'lib/mongoid/contextual/none.rb', line 120 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
17 18 19 |
# File 'lib/mongoid/contextual/none.rb', line 17 def criteria @criteria end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
17 18 19 |
# File 'lib/mongoid/contextual/none.rb', line 17 def klass @klass end |
Instance Method Details
#==(other) ⇒ true | false
Check if the context is equal to the other object.
27 28 29 |
# File 'lib/mongoid/contextual/none.rb', line 27 def ==(other) other.is_a?(None) end |
#distinct(_field) ⇒ Array
Get the distinct field values in null context.
39 40 41 |
# File 'lib/mongoid/contextual/none.rb', line 39 def distinct(_field) [] end |
#each ⇒ Enumerator
Iterate over the null context. There are no documents to iterate over in this case.
52 53 54 55 56 57 58 59 |
# File 'lib/mongoid/contextual/none.rb', line 52 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.
76 |
# File 'lib/mongoid/contextual/none.rb', line 76 def exists?(id_or_conditions = :none); false; end |
#fifth ⇒ nil
Always returns nil.
256 257 258 |
# File 'lib/mongoid/contextual/none.rb', line 256 def fifth nil end |
#fifth! ⇒ Object
Always raises an error.
266 267 268 |
# File 'lib/mongoid/contextual/none.rb', line 266 def fifth! raise_document_not_found_error end |
#first(limit = nil) ⇒ [] | nil Also known as: find_first, one
Always returns nil.
132 133 134 |
# File 'lib/mongoid/contextual/none.rb', line 132 def first(limit = nil) [] unless limit.nil? end |
#first! ⇒ Object
Always raises an error.
142 143 144 |
# File 'lib/mongoid/contextual/none.rb', line 142 def first! raise_document_not_found_error end |
#fourth ⇒ nil
Always returns nil.
236 237 238 |
# File 'lib/mongoid/contextual/none.rb', line 236 def fourth nil end |
#fourth! ⇒ Object
Always raises an error.
246 247 248 |
# File 'lib/mongoid/contextual/none.rb', line 246 def fourth! raise_document_not_found_error end |
#last(limit = nil) ⇒ [] | nil
Always returns nil.
154 155 156 |
# File 'lib/mongoid/contextual/none.rb', line 154 def last(limit = nil) [] unless limit.nil? end |
#last! ⇒ Object
Always raises an error.
164 165 166 |
# File 'lib/mongoid/contextual/none.rb', line 164 def last! raise_document_not_found_error end |
#length ⇒ Integer Also known as: size
Always returns zero.
316 317 318 |
# File 'lib/mongoid/contextual/none.rb', line 316 def length entries.length end |
#pick(*_fields) ⇒ nil
Pick the field values in null context.
98 99 100 |
# File 'lib/mongoid/contextual/none.rb', line 98 def pick(*_fields) nil end |
#pluck(*_fields) ⇒ Array
Pluck the field values in null context.
86 87 88 |
# File 'lib/mongoid/contextual/none.rb', line 86 def pluck(*_fields) [] end |
#second ⇒ nil
Always returns nil.
196 197 198 |
# File 'lib/mongoid/contextual/none.rb', line 196 def second nil end |
#second! ⇒ Object
Always raises an error.
206 207 208 |
# File 'lib/mongoid/contextual/none.rb', line 206 def second! raise_document_not_found_error end |
#second_to_last ⇒ nil
Always returns nil.
276 277 278 |
# File 'lib/mongoid/contextual/none.rb', line 276 def second_to_last nil end |
#second_to_last! ⇒ Object
Always raises an error.
286 287 288 |
# File 'lib/mongoid/contextual/none.rb', line 286 def second_to_last! raise_document_not_found_error end |
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
176 177 178 |
# File 'lib/mongoid/contextual/none.rb', line 176 def take(limit = nil) limit ? [] : nil end |
#take! ⇒ Object
Always raises an error.
186 187 188 |
# File 'lib/mongoid/contextual/none.rb', line 186 def take! raise_document_not_found_error end |
#tally(_field) ⇒ Hash
Tally the field values in null context.
110 111 112 |
# File 'lib/mongoid/contextual/none.rb', line 110 def tally(_field) {} end |
#third ⇒ nil
Always returns nil.
216 217 218 |
# File 'lib/mongoid/contextual/none.rb', line 216 def third nil end |
#third! ⇒ Object
Always raises an error.
226 227 228 |
# File 'lib/mongoid/contextual/none.rb', line 226 def third! raise_document_not_found_error end |
#third_to_last ⇒ nil
Always returns nil.
296 297 298 |
# File 'lib/mongoid/contextual/none.rb', line 296 def third_to_last nil end |
#third_to_last! ⇒ Object
Always raises an error.
306 307 308 |
# File 'lib/mongoid/contextual/none.rb', line 306 def third_to_last! raise_document_not_found_error end |