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.
-
#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.
115 116 117 |
# File 'lib/mongoid/contextual/none.rb', line 115 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
12 13 14 |
# File 'lib/mongoid/contextual/none.rb', line 12 def criteria @criteria end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
12 13 14 |
# File 'lib/mongoid/contextual/none.rb', line 12 def klass @klass end |
Instance Method Details
#==(other) ⇒ true | false
Check if the context is equal to the other object.
22 23 24 |
# File 'lib/mongoid/contextual/none.rb', line 22 def ==(other) other.is_a?(None) end |
#distinct(_field) ⇒ Array
Get the distinct field values in null context.
34 35 36 |
# File 'lib/mongoid/contextual/none.rb', line 34 def distinct(_field) [] end |
#each ⇒ Enumerator
Iterate over the null context. There are no documents to iterate over in this case.
47 48 49 50 51 52 53 54 |
# File 'lib/mongoid/contextual/none.rb', line 47 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.
71 |
# File 'lib/mongoid/contextual/none.rb', line 71 def exists?(id_or_conditions = :none); false; end |
#fifth ⇒ nil
Always returns nil.
251 252 253 |
# File 'lib/mongoid/contextual/none.rb', line 251 def fifth nil end |
#fifth! ⇒ Object
Always raises an error.
261 262 263 |
# File 'lib/mongoid/contextual/none.rb', line 261 def fifth! raise_document_not_found_error end |
#first(limit = nil) ⇒ [] | nil Also known as: find_first, one
Always returns nil.
127 128 129 |
# File 'lib/mongoid/contextual/none.rb', line 127 def first(limit = nil) [] unless limit.nil? end |
#first! ⇒ Object
Always raises an error.
137 138 139 |
# File 'lib/mongoid/contextual/none.rb', line 137 def first! raise_document_not_found_error end |
#fourth ⇒ nil
Always returns nil.
231 232 233 |
# File 'lib/mongoid/contextual/none.rb', line 231 def fourth nil end |
#fourth! ⇒ Object
Always raises an error.
241 242 243 |
# File 'lib/mongoid/contextual/none.rb', line 241 def fourth! raise_document_not_found_error end |
#last(limit = nil) ⇒ [] | nil
Always returns nil.
149 150 151 |
# File 'lib/mongoid/contextual/none.rb', line 149 def last(limit = nil) [] unless limit.nil? end |
#last! ⇒ Object
Always raises an error.
159 160 161 |
# File 'lib/mongoid/contextual/none.rb', line 159 def last! raise_document_not_found_error end |
#length ⇒ Integer Also known as: size
Always returns zero.
311 312 313 |
# File 'lib/mongoid/contextual/none.rb', line 311 def length entries.length end |
#pick(*_fields) ⇒ nil
Pick the field values in null context.
93 94 95 |
# File 'lib/mongoid/contextual/none.rb', line 93 def pick(*_fields) nil end |
#pluck(*_fields) ⇒ Array
Pluck the field values in null context.
81 82 83 |
# File 'lib/mongoid/contextual/none.rb', line 81 def pluck(*_fields) [] end |
#second ⇒ nil
Always returns nil.
191 192 193 |
# File 'lib/mongoid/contextual/none.rb', line 191 def second nil end |
#second! ⇒ Object
Always raises an error.
201 202 203 |
# File 'lib/mongoid/contextual/none.rb', line 201 def second! raise_document_not_found_error end |
#second_to_last ⇒ nil
Always returns nil.
271 272 273 |
# File 'lib/mongoid/contextual/none.rb', line 271 def second_to_last nil end |
#second_to_last! ⇒ Object
Always raises an error.
281 282 283 |
# File 'lib/mongoid/contextual/none.rb', line 281 def second_to_last! raise_document_not_found_error end |
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
171 172 173 |
# File 'lib/mongoid/contextual/none.rb', line 171 def take(limit = nil) limit ? [] : nil end |
#take! ⇒ Object
Always raises an error.
181 182 183 |
# File 'lib/mongoid/contextual/none.rb', line 181 def take! raise_document_not_found_error end |
#tally(_field) ⇒ Hash
Tally the field values in null context.
105 106 107 |
# File 'lib/mongoid/contextual/none.rb', line 105 def tally(_field) {} end |
#third ⇒ nil
Always returns nil.
211 212 213 |
# File 'lib/mongoid/contextual/none.rb', line 211 def third nil end |
#third! ⇒ Object
Always raises an error.
221 222 223 |
# File 'lib/mongoid/contextual/none.rb', line 221 def third! raise_document_not_found_error end |
#third_to_last ⇒ nil
Always returns nil.
291 292 293 |
# File 'lib/mongoid/contextual/none.rb', line 291 def third_to_last nil end |
#third_to_last! ⇒ Object
Always raises an error.
301 302 303 |
# File 'lib/mongoid/contextual/none.rb', line 301 def third_to_last! raise_document_not_found_error end |