Module: Mongoid::Document::ClassMethods

Defined in:
lib/mongoid/document.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#===(other) ⇒ true, false

Performs class equality checking.

Examples:

Compare the classes.

document === other

Parameters:

Returns:

  • (true, false)

    True if the classes are equal, false if not.

Since:

  • 2.0.0.rc.4



282
283
284
# File 'lib/mongoid/document.rb', line 282

def ===(other)
  other.class == Class ? self <= other : other.is_a?(self)
end

#_typesArray<Class>

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

Examples:

Get the types.

document._types

Returns:

  • (Array<Class>)

    All subclasses of the current document.



311
312
313
# File 'lib/mongoid/document.rb', line 311

def _types
  @_type ||= [descendants + [self]].flatten.uniq.map { |t| t.to_s }
end

#i18n_scopeSymbol

Set the i18n scope to overwrite ActiveModel.

Returns:



318
319
320
# File 'lib/mongoid/document.rb', line 318

def i18n_scope
  :mongoid
end

#instantiate(attrs = nil) ⇒ Document

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

Examples:

Create the document.

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

Parameters:

  • attrs (Hash) (defaults to: nil)

    The hash of attributes to instantiate with.

Returns:



295
296
297
298
299
300
301
302
303
# File 'lib/mongoid/document.rb', line 295

def instantiate(attrs = nil)
  attributes = attrs || {}
  allocate.tap do |doc|
    doc.instance_variable_set(:@attributes, attributes)
    doc.apply_defaults
    IdentityMap.set(doc) unless _loading_revision?
    doc.run_callbacks(:initialize) { doc }
  end
end

#loggerLogger

Returns the logger

Examples:

Get the logger.

Person.logger

Returns:

  • (Logger)

    The configured logger or a default Logger instance.

Since:

  • 2.2.0



330
331
332
# File 'lib/mongoid/document.rb', line 330

def logger
  Mongoid.logger
end