class Mongoid::Contextual::None

Attributes

criteria[R]
klass[R]

Public Class Methods

new(criteria) click to toggle source

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

==(other) click to toggle source

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
distinct(field) click to toggle source

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
each() { |doc| ... } click to toggle source

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
exists?() click to toggle source

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
last() click to toggle source

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
length() click to toggle source

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
Also aliased as: size
pluck(*args) click to toggle source

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
size()
Alias for: length