module Mongoid::Document::ClassMethods

Public Instance Methods

===(other) click to toggle source

Performs class equality checking.

@example Compare the classes.

document === other

@param [ Document, Object ] other The other object to compare with.

@return [ true, false ] True if the classes are equal, false if not.

@since 2.0.0.rc.4

# File lib/mongoid/document.rb, line 306
def ===(other)
  other.class == Class ? self <= other : other.is_a?(self)
end
_mongoid_clear_types() click to toggle source

Clear the @_type cache. This is generally called when changing the discriminator key/value on a class.

@example Get the types.

document._mongoid_clear_types

@api private

# File lib/mongoid/document.rb, line 354
def _mongoid_clear_types
  @_type = nil
  superclass._mongoid_clear_types if hereditary?
end
_types() click to toggle source

Returns all types to query for when using this class as the base.

@example Get the types.

document._types

@return [ Array<Class> ] All subclasses of the current document.

@since 1.0.0

# File lib/mongoid/document.rb, line 343
def _types
  @_type ||= (descendants + [ self ]).uniq.map(&:discriminator_value)
end
i18n_scope() click to toggle source

Set the i18n scope to overwrite ActiveModel.

@return [ Symbol ] :mongoid

@since 2.0.0

# File lib/mongoid/document.rb, line 364
def i18n_scope
  :mongoid
end
instantiate(attrs = nil, selected_fields = nil) { |doc| ... } click to toggle source

Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.

@example Create the document.

Person.instantiate(:title => "Sir", :age => 30)

@param [ Hash ] attrs The hash of attributes to instantiate with. @param [ Integer ] selected_fields The selected fields from the

criteria.

@return [ Document ] A new document.

@since 1.0.0

# File lib/mongoid/document.rb, line 323
def instantiate(attrs = nil, selected_fields = nil)
  attributes = attrs || {}
  doc = allocate
  doc.__selected_fields = selected_fields
  doc.instance_variable_set(:@attributes, attributes)
  doc.apply_defaults
  yield(doc) if block_given?
  doc.run_callbacks(:find) unless doc._find_callbacks.empty?
  doc.run_callbacks(:initialize) unless doc._initialize_callbacks.empty?
  doc
end
logger() click to toggle source

Returns the logger

@example Get the logger.

Person.logger

@return [ Logger ] The configured logger or a default Logger instance.

@since 2.2.0

# File lib/mongoid/document.rb, line 376
def logger
  Mongoid.logger
end