Class: Mongoid::Contextual::None
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Queryable ,
Aggregable::None ,
Enumerable
|
|
Inherits: | Object |
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.
Class Method Summary
-
.new(criteria) ⇒ None
constructor
Create the new null context.
Instance Attribute Summary
Queryable
- Included
#blank? | Is the enumerable of matching documents empty? |
#collection, #collection The collection to query against., #criteria, #criteria The criteria for the context., | |
#empty? | Alias for Queryable#blank?. |
#klass, #klass The klass for the criteria. |
Instance Method Summary
-
#==(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!
Always raises an error.
-
#find_first(limit = nil)
Alias for #first.
-
#first(limit = nil) ⇒ [] | nil
(also: #find_first, #one)
Always returns nil.
-
#first!
Always raises an error.
-
#fourth ⇒ nil
Always returns nil.
-
#fourth!
Always raises an error.
-
#last(limit = nil) ⇒ [] | nil
Always returns nil.
-
#last!
Always raises an error.
-
#length ⇒ Integer
(also: #size)
Always returns zero.
-
#one(limit = nil)
Alias for #first.
-
#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!
Always raises an error.
-
#second_to_last ⇒ nil
Always returns nil.
-
#second_to_last!
Always raises an error.
-
#size
Alias for #length.
-
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
-
#take!
Always raises an error.
-
#tally(_field) ⇒ Hash
Tally the field values in null context.
-
#third ⇒ nil
Always returns nil.
-
#third!
Always raises an error.
-
#third_to_last ⇒ nil
Always returns nil.
-
#third_to_last!
Always raises an error.
- #raise_document_not_found_error private
Aggregable::None
- Included
#aggregates | Get all the aggregate values for the provided field in null context. |
#avg | Always returns nil. |
#max | Alias for Aggregable::None#min. |
#min | Always returns nil. |
#sum | Always returns zero. |
Constructor Details
.new(criteria) ⇒ None
Create the new null context.
Instance Attribute Details
#criteria (readonly)
[ GitHub ]# File 'lib/mongoid/contextual/none.rb', line 17
attr_reader :criteria, :klass
#klass (readonly)
[ GitHub ]# File 'lib/mongoid/contextual/none.rb', line 17
attr_reader :criteria, :klass
Instance Method Details
#==(other) ⇒ true
| false
Check if the context is equal to the other object.
# 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.
# 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.
# 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.
# File 'lib/mongoid/contextual/none.rb', line 76
def exists?(id_or_conditions = :none); false; end
#fifth ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 256
def fifth nil end
#fifth!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 266
def fifth! raise_document_not_found_error end
#find_first(limit = nil)
Alias for #first.
# File 'lib/mongoid/contextual/none.rb', line 321
alias :find_first :first
#first(limit = nil) ⇒ [] | nil
Also known as: #find_first, #one
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 132
def first(limit = nil) [] unless limit.nil? end
#first!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 142
def first! raise_document_not_found_error end
#fourth ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 236
def fourth nil end
#fourth!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 246
def fourth! raise_document_not_found_error end
#last(limit = nil) ⇒ [] | nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 154
def last(limit = nil) [] unless limit.nil? end
#last!
Always raises an error.
# 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.
# File 'lib/mongoid/contextual/none.rb', line 316
def length entries.length end
#one(limit = nil)
Alias for #first.
# File 'lib/mongoid/contextual/none.rb', line 322
alias :one :first
#pick(*_fields) ⇒ nil
Pick the field values in null context.
# File 'lib/mongoid/contextual/none.rb', line 98
def pick(*_fields) nil end
#pluck(*_fields) ⇒ Array
Pluck the field values in null context.
# File 'lib/mongoid/contextual/none.rb', line 86
def pluck(*_fields) [] end
#raise_document_not_found_error (private)
# File 'lib/mongoid/contextual/none.rb', line 326
def raise_document_not_found_error raise Errors::DocumentNotFound.new(klass, nil, nil) end
#second ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 196
def second nil end
#second!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 206
def second! raise_document_not_found_error end
#second_to_last ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 276
def second_to_last nil end
#second_to_last!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 286
def second_to_last! raise_document_not_found_error end
#size
Alias for #length.
# File 'lib/mongoid/contextual/none.rb', line 319
alias :size :length
#take(limit = nil) ⇒ [] | nil
Returns nil or empty array.
# File 'lib/mongoid/contextual/none.rb', line 176
def take(limit = nil) limit ? [] : nil end
#take!
Always raises an error.
# 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.
# File 'lib/mongoid/contextual/none.rb', line 110
def tally(_field) {} end
#third ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 216
def third nil end
#third!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 226
def third! raise_document_not_found_error end
#third_to_last ⇒ nil
Always returns nil.
# File 'lib/mongoid/contextual/none.rb', line 296
def third_to_last nil end
#third_to_last!
Always raises an error.
# File 'lib/mongoid/contextual/none.rb', line 306
def third_to_last! raise_document_not_found_error end