Class: Mongoid::Identity

Inherits:
Object show all
Defined in:
lib/mongoid/identity.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Identity

Create the new identity generator - this will be expanded in the future to support pk generators.

Examples:

Identity.new(document)

Parameters:

  • document (Document)

    The document to generate an id for.



27
28
29
# File 'lib/mongoid/identity.rb', line 27

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'lib/mongoid/identity.rb', line 5

def document
  @document
end

Instance Method Details

#createObject

Create the identity for the document. The id will be set in either in the form of a Mongo object id or a composite key set up by defining a key on the document. The _type will be set to the document’s class name.

Examples:

Create the id and set the type.

identity.create


14
15
16
# File 'lib/mongoid/identity.rb', line 14

def create
  identify.tap { type }
end