123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Clients::Options::ClassMethods

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/clients/options.rb

Instance Method Summary

Instance Method Details

#client_nameString

Get the database client name for the current persistence context of the document class.

Examples:

Get the client name for the current persistence context.

Model.client_name

Returns:

  • (String)

    The database client name for the current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 146

def client_name
  persistence_context.client_name
end

#collectionMongo::Collection

Get the collection for the current persistence context of the document class.

Examples:

Get the collection for the current persistence context.

Model.collection

Returns:

  • (Mongo::Collection)

    The collection for the current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 182

def collection
  persistence_context.collection
end

#collection_nameString

Get the collection name for the current persistence context of the document class.

Examples:

Get the collection name for the current persistence context.

Model.collection_name

Returns:

  • (String)

    The collection name for the current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 158

def collection_name
  persistence_context.collection_name
end

#database_nameString

Get the database name for the current persistence context of the document class.

Examples:

Get the database name for the current persistence context.

Model.database_name

Returns:

  • (String)

    The database name for the current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 170

def database_name
  persistence_context.database_name
end

#mongo_clientMongo::Client

Get the client for the current persistence context of the document class.

Examples:

Get the client for the current persistence context.

Model.mongo_client

Returns:

  • (Mongo::Client)

    The client for the current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 194

def mongo_client
  persistence_context.client
end

#persistence_contextMongoid::PersistenceContent

Get the current persistence context of the document class. If a persistence context is not set, a new one will be initialized and returned.

Examples:

Get the current persistence context.

Model.persistence_context

Returns:

  • (Mongoid::PersistenceContent)

    The current persistence context.

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 228

def persistence_context
  PersistenceContext.get(self) || PersistenceContext.new(self)
end

#with(options, &block)

Change the persistence context for this class during the block.

Examples:

Save the current document to a different collection.

Model.with(collection: "bands") do |m|
  m.create
end

Parameters:

  • options (Hash)

    The storage options.

Options Hash (options):

[ GitHub ]

  
# File 'lib/mongoid/clients/options.rb', line 210

def with(options, &block)
  original_context = PersistenceContext.get(self)
  original_cluster = persistence_context.cluster
  PersistenceContext.set(self, options)
  yield self
ensure
  PersistenceContext.clear(self, original_cluster, original_context)
end