module Mongoid::Document::ClassMethods
Public Instance Methods
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 275 def ===(other) other.class == Class ? self <= other : other.is_a?(self) end
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 313 def _types @_type ||= (descendants + [ self ]).uniq.map { |t| t.to_s } end
Set the i18n scope to overwrite ActiveModel.
@return [ Symbol ] :mongoid
@since 2.0.0
# File lib/mongoid/document.rb, line 322 def i18n_scope :mongoid end
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 ] criteria_instance_id The criteria id that
instantiated the document.
@return [ Document ] A new document.
@since 1.0.0
# File lib/mongoid/document.rb, line 292 def instantiate(attrs = nil, criteria_instance_id = nil) attributes = attrs || {} doc = allocate doc.criteria_instance_id = criteria_instance_id doc.instance_variable_set(:@attributes, attributes) doc.apply_defaults IdentityMap.set(doc) unless _loading_revision? 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
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 334 def logger Mongoid.logger end