class Mongoid::Contextual::None
Attributes
Public Class Methods
Create the new null context.
@example Create the new context.
Null.new(criteria)
@param [ Criteria
] criteria The criteria.
@since 4.0.0
# File lib/mongoid/contextual/none.rb, line 89 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 22 def ==(other) other.is_a?(None) end
Allow distinct for null context.
@example Get the distinct values.
context.distinct(:name)
@param [ String, Symbol ] field the name of the field.
@return [ Array ] Empty Array
# File lib/mongoid/contextual/none.rb, line 34 def distinct(field) [] 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 49 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 66 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 101 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 111 def length entries.length end
Allow pluck for null context.
@example Allow pluck for null context.
context.pluck(:name)
@param [ String, Symbol, Array ] args Field or fields to pluck.
@return [ Array ] Emtpy Array
# File lib/mongoid/contextual/none.rb, line 77 def pluck(*args) [] end