123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Clients::StorageOptions::ClassMethods

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

Instance Method Summary

Instance Method Details

#reset_storage_options!

Reset the store_in options

Examples:

Reset the store_in options

Model.reset_storage_options!
[ GitHub ]

  
# File 'lib/mongoid/clients/storage_options.rb', line 92

def reset_storage_options!
  self.storage_options = storage_options_defaults.dup
  PersistenceContext.clear(self)
end

#storage_options_defaultsHash

Get the default storage options.

Examples:

Get the default storage options.

Model.storage_options_defaults

Returns:

  • (Hash)

    Default storage options.

[ GitHub ]

  
# File 'lib/mongoid/clients/storage_options.rb', line 103

def storage_options_defaults
  {
    collection: name.collectionize.to_sym,
    client: :default
  }
end

#store_in(options) ⇒ Class

Give this model specific custom default storage options.

Examples:

Store this model by default in “artists”

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

Store this model by default in the sharded db.

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

Store this model by default in a different client.

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

Store this model with a combination of options.

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

Parameters:

  • options (Hash)

    The storage options.

Options Hash (options):

Returns:

  • (Class)

    The model class.

[ GitHub ]

  
# File 'lib/mongoid/clients/storage_options.rb', line 83

def store_in(options)
  Validators::Storage.validate(self, options)
  self.storage_options = self.storage_options.merge(options)
end