Class: Mongoid::Contextual::None
- Inherits:
-
Object
- Object
- Mongoid::Contextual::None
- Includes:
- Enumerable, 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.
-
#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.
75 76 77 |
# File 'lib/mongoid/contextual/none.rb', line 75 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
8 9 10 |
# File 'lib/mongoid/contextual/none.rb', line 8 def criteria @criteria end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/mongoid/contextual/none.rb', line 8 def klass @klass end |
Instance Method Details
#==(other) ⇒ true, false
Check if the context is equal to the other object.
20 21 22 |
# File 'lib/mongoid/contextual/none.rb', line 20 def ==(other) other.is_a?(None) end |
#each ⇒ Enumerator
Iterate over the null context. There are no documents to iterate over in this case.
35 36 37 38 39 40 41 42 |
# File 'lib/mongoid/contextual/none.rb', line 35 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.
52 |
# File 'lib/mongoid/contextual/none.rb', line 52 def exists?; false; end |
#last ⇒ nil
Always returns nil.
87 |
# File 'lib/mongoid/contextual/none.rb', line 87 def last; nil; end |
#length ⇒ Integer Also known as: size
Always returns zero.
97 98 99 |
# File 'lib/mongoid/contextual/none.rb', line 97 def length entries.length end |
#pluck(*args) ⇒ Array
Allow pluck for null context.
63 64 65 |
# File 'lib/mongoid/contextual/none.rb', line 63 def pluck(*args) [] end |