Class: Mongoid::Contextual::None
- Inherits:
-
Object
- Object
- Mongoid::Contextual::None
- Includes:
- Enumerable, Queryable
- Defined in:
- build/mongoid-7.3/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
Allow distinct for null context.
-
#each ⇒ Enumerator
Iterate over the null context.
-
#exists? ⇒ true, 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.
-
#pluck(*args) ⇒ Array
Allow pluck for null context.
Methods included from Queryable
Constructor Details
#initialize(criteria) ⇒ None
Create the new null context.
89 90 91 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 89 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
10 11 12 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 10 def criteria @criteria end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
10 11 12 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 10 def klass @klass end |
Instance Method Details
#==(other) ⇒ true, false
Check if the context is equal to the other object.
22 23 24 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 22 def ==(other) other.is_a?(None) end |
#distinct(field) ⇒ Array
Allow distinct for null context.
34 35 36 |
# File 'build/mongoid-7.3/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.
49 50 51 52 53 54 55 56 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 49 def each if block_given? [].each { |doc| yield(doc) } self else to_enum end end |
#exists? ⇒ true, false
Do any documents exist for the context.
66 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 66 def exists?; false; end |
#last ⇒ nil
Always returns nil.
101 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 101 def last; nil; end |
#length ⇒ Integer Also known as: size
Always returns zero.
111 112 113 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 111 def length entries.length end |
#pluck(*args) ⇒ Array
Allow pluck for null context.
77 78 79 |
# File 'build/mongoid-7.3/lib/mongoid/contextual/none.rb', line 77 def pluck(*args) [] end |