Module: Mongoid::Sessions::Options::ClassMethods

Includes:
Threaded
Defined in:
lib/mongoid/sessions/options.rb

Instance Method Summary collapse

Methods included from Threaded

#persistence_options

Instance Method Details

#collection_nameObject



98
99
100
101
102
103
# File 'lib/mongoid/sessions/options.rb', line 98

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

#database_nameObject



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

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

#session_nameObject



91
92
93
94
95
96
# File 'lib/mongoid/sessions/options.rb', line 91

def session_name
  if persistence_options && v = persistence_options[:session]
    return v.to_sym
  end
  super
end

#with(options) ⇒ Class

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

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 session.

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

Create with a combination of options.

Model.with(session: "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.

  • :session (String, Symbol)

    The session name.

Returns:

  • (Class)

    The model class.

Since:

  • 3.0.0



136
137
138
# File 'lib/mongoid/sessions/options.rb', line 136

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