class Mongoid::Contextual::None
Attributes
Public Class Methods
Create the new null context.
@example Create the new context.
Null.new(criteria)
@param [ Criteria
] The criteria.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 75 def initialize(criteria) @criteria, @klass = criteria, criteria.klass end
Public Instance Methods
Check if the context is equal to the other object.
@example Check equality.
context == []
@param [ Array ] other The other array.
@return [ true, false ] If the objects are equal.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 20 def ==(other) other.is_a?(None) end
Iterate over the null context. There are no documents to iterate over in this case.
@example Iterate over the context.
context.each do |doc| puts doc.name end
@return [ Enumerator ] The enumerator.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 35 def each if block_given? [].each { |doc| yield(doc) } self else to_enum end end
Do any documents exist for the context.
@example Do any documents exist for the context.
context.exists?
@return [ true, false ] If the count is more than zero.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 52 def exists?; false; end
Always returns nil.
@example Get the last document.
context.last
@return [ nil ] Always nil.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 87 def last; nil; end
Always returns zero.
@example Get the length of matching documents.
context.length
@return [ Integer ] Always zero.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 97 def length entries.length end
Allow pluck for null context.
@example Allow pluck for null context.
context.pluck(:name)
@param [ String, Symbol
, Array ] field or fields to pluck.
@return [ Array ] Emtpy Array
# File lib/mongoid/contextual/none.rb, line 63 def pluck(*args) [] end