Module: Mongoid::Sessions::Factory

Extended by:
Factory
Included in:
Factory
Defined in:
lib/mongoid/sessions/factory.rb

Instance Method Summary collapse

Instance Method Details

#create(name = nil) ⇒ Moped::Session

Create a new session given the named configuration. If no name is provided, return a new session with the default configuration. If a name is provided for which no configuration exists, an error will be raised.

Examples:

Create the session.

Factory.create(:secondary)

Parameters:

  • name (String, Symbol) (defaults to: nil)

    The named session configuration.

Returns:

  • (Moped::Session)

    The new session.

Raises:

Since:

  • 3.0.0



24
25
26
27
28
29
# File 'lib/mongoid/sessions/factory.rb', line 24

def create(name = nil)
  return default unless name
  config = Mongoid.sessions[name]
  raise Errors::NoSessionConfig.new(name) unless config
  create_session(config)
end

#defaultMoped::Session

Get the default session.

Examples:

Get the default session.

Factory.default

Returns:

  • (Moped::Session)

    The default session.

Raises:

Since:

  • 3.0.0



42
43
44
# File 'lib/mongoid/sessions/factory.rb', line 42

def default
  create_session(Mongoid.sessions[:default])
end