module Mongoid::Clients::StorageOptions::ClassMethods

Public Instance Methods

reset_storage_options!() click to toggle source

Reset the store_in options

@example Reset the store_in options

Model.reset_storage_options!

@since 4.0.0

# File lib/mongoid/clients/storage_options.rb, line 64
def reset_storage_options!
  self.storage_options = storage_options_defaults.dup
  PersistenceContext.clear(self)
end
storage_options_defaults() click to toggle source

Get the default storage options.

@example Get the default storage options.

Model.storage_options_defaults

@return [ Hash ] Default storage options.

@since 4.0.0

# File lib/mongoid/clients/storage_options.rb, line 77
def storage_options_defaults
  {
    collection: name.collectionize.to_sym,
    client: :default
  }
end
store_in(options) click to toggle source

Give this model specific custom default storage options.

@example Store this model by default in “artists”

class Band
  include Mongoid::Document
  store_in collection: "artists"
end

@example Store this model by default in the sharded db.

class Band
  include Mongoid::Document
  store_in database: "echo_shard"
end

@example Store this model by default in a different client.

class Band
  include Mongoid::Document
  store_in client: "analytics"
end

@example Store this model with a combination of options.

class Band
  include Mongoid::Document
  store_in collection: "artists", database: "music"
end

@param [ Hash ] options The storage options.

@option options [ String | Symbol ] :collection The collection name. @option options [ String | Symbol ] :database The database name. @option options [ String | Symbol ] :client The client name.

@return [ Class ] The model class.

@since 3.0.0

# File lib/mongoid/clients/storage_options.rb, line 53
def store_in(options)
  Validators::Storage.validate(self, options)
  storage_options.merge!(options)
end