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

Extended by:
Gem::Deprecate
Includes:
Threaded
Defined in:
lib/mongoid/clients/options.rb

Instance Method Summary collapse

Methods included from Threaded

#persistence_options

Instance Method Details

#client_nameObject Also known as: session_name



105
106
107
108
109
110
# File 'lib/mongoid/clients/options.rb', line 105

def client_name
  if persistence_options && v = persistence_options[:client]
    return v.to_sym
  end
  super
end

#collection_nameObject



114
115
116
117
118
119
# File 'lib/mongoid/clients/options.rb', line 114

def collection_name
  if persistence_options && v = persistence_options[:collection]
    return v.to_sym
  end
  super
end

#database_nameObject



121
122
123
124
125
126
# File 'lib/mongoid/clients/options.rb', line 121

def database_name
  if persistence_options && v = persistence_options[:database]
    return v.to_sym
  end
  super
end

#with(options) ⇒ Class

Tell the next persistance operation to store in a specific collection, database or client.

Examples:

Create a document in a different collection.

Model.with(collection: "secondary").create(name: "test")

Create a document in a different database.

Model.with(database: "secondary").create(name: "test")

Create a document in a different client.

Model.with(client: "secondary").create(name: "test")

Create with a combination of options.

Model.with(client: "sharded", database: "secondary").create

Parameters:

  • options (Hash)

    The storage options.

Options Hash (options):

  • :collection (String, Symbol)

    The collection name.

  • :database (String, Symbol)

    The database name.

  • :client (String, Symbol)

    The client name.

Returns:

  • (Class)

    The model class.

Since:

  • 3.0.0



152
153
154
# File 'lib/mongoid/clients/options.rb', line 152

def with(options)
  Proxy.new(self, (persistence_options || {}).merge(options))
end