Module: Mongoid::Clients::StorageOptions

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Clients
Defined in:
lib/mongoid/clients/storage_options.rb

Overview

Mixin module included into Mongoid::Document which adds the ability to set the collection in which to store the document by default.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#remembered_storage_optionsHash | nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Remembers the storage options that were active when the current object was instantiated/created.

Returns:

  • (Hash | nil)

    the storage options that have been cached for this object instance (or nil if no storage options have been cached).



25
26
27
# File 'lib/mongoid/clients/storage_options.rb', line 25

def remembered_storage_options
  @remembered_storage_options
end

Instance Method Details

#remember_storage_options!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Saves the storage options from the current persistence context.



41
42
43
44
45
46
# File 'lib/mongoid/clients/storage_options.rb', line 41

def remember_storage_options!
  return if Mongoid.legacy_persistence_context_behavior

  opts = persistence_context.requested_storage_options
  self.remembered_storage_options = opts if opts
end

#storage_optionsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The storage options that apply to this record, consisting of both the class-level declared storage options (e.g. store_in) merged with any remembered storage options.

Returns:

  • (Hash)

    the storage options for the record



34
35
36
# File 'lib/mongoid/clients/storage_options.rb', line 34

def storage_options
  self.class.storage_options.merge(remembered_storage_options || {})
end