Class: Moped::Session
- Defined in:
- lib/moped/session.rb,
lib/moped/session/context.rb
Overview
A session in moped is root for all interactions with a MongoDB server or replica set.
It can talk to a single default database, or dynamically speak to multiple databases.
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
- #cluster The session cluster.(Thesessioncluster.) ⇒ Object readonly
-
#context ⇒ Object
readonly
Returns the value of attribute context.
- #context The session context.(Thesessioncontext.) ⇒ Object readonly
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #options The session options.(Thesessionoptions.) ⇒ Object readonly
Instance Method Summary collapse
-
#[](name) ⇒ Collection
Return
collection
from the current database. -
#collection_names ⇒ Array<String>
Return non system collection name from the current database.
-
#collections ⇒ Array<Collection>
Return non system collection name from the current database.
-
#command(op) ⇒ Hash
Run
command
on the current database. -
#consistency ⇒ :strong, :eventual
Get the session’s consistency.
-
#drop ⇒ nil
Drop the current database.
-
#initialize(seeds, options = {}) ⇒ Session
constructor
Initialize a new database session.
-
#login(username, password) ⇒ Object
Log in with
username
andpassword
on the current database. -
#logout ⇒ Object
Log out from the current database.
-
#new(options = {}) {|session| ... } ⇒ Session
Create a new session with
options
and use new socket connections. -
#safe? ⇒ true, false
Is the session operating in safe mode?.
-
#safety ⇒ Boolean, Hash
Get the safety level for the session.
-
#use(database) ⇒ Object
Switch the session’s current database.
-
#with(options = {}) {|session| ... } ⇒ Session, Object
Create a new session with
options
reusing existing connections.
Constructor Details
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
35 36 37 |
# File 'lib/moped/session.rb', line 35 def cluster @cluster end |
#cluster The session cluster.(Thesessioncluster.) ⇒ Object (readonly)
35 |
# File 'lib/moped/session.rb', line 35 attr_reader :cluster, :context, :options |
#context ⇒ Object (readonly)
Returns the value of attribute context.
35 36 37 |
# File 'lib/moped/session.rb', line 35 def context @context end |
#context The session context.(Thesessioncontext.) ⇒ Object (readonly)
35 |
# File 'lib/moped/session.rb', line 35 attr_reader :cluster, :context, :options |
#options ⇒ Object (readonly)
Returns the value of attribute options.
35 36 37 |
# File 'lib/moped/session.rb', line 35 def @options end |
#options The session options.(Thesessionoptions.) ⇒ Object (readonly)
35 |
# File 'lib/moped/session.rb', line 35 attr_reader :cluster, :context, :options |
Instance Method Details
#[](name) ⇒ Collection
Return collection
from the current database.
44 45 46 |
# File 'lib/moped/session.rb', line 44 def [](name) current_database[name] end |
#collection_names ⇒ Array<String>
Return non system collection name from the current database.
55 56 57 |
# File 'lib/moped/session.rb', line 55 def collection_names current_database.collection_names end |
#collections ⇒ Array<Collection>
Return non system collection name from the current database.
66 67 68 |
# File 'lib/moped/session.rb', line 66 def collections current_database.collections end |
#command(op) ⇒ Hash
Run command
on the current database.
77 78 79 |
# File 'lib/moped/session.rb', line 77 def command(op) current_database.command(op) end |
#consistency ⇒ :strong, :eventual
Get the session’s consistency.
122 123 124 |
# File 'lib/moped/session.rb', line 122 def consistency [:consistency] end |
#drop ⇒ nil
Drop the current database.
88 89 90 |
# File 'lib/moped/session.rb', line 88 def drop current_database.drop end |
#login(username, password) ⇒ Object
Log in with username
and password
on the current database.
99 100 101 |
# File 'lib/moped/session.rb', line 99 def login(username, password) current_database.login(username, password) end |
#logout ⇒ Object
Log out from the current database.
110 111 112 |
# File 'lib/moped/session.rb', line 110 def logout current_database.logout end |
#new(options = {}) {|session| ... } ⇒ Session
Create a new session with options
and use new socket connections.
180 181 182 183 184 185 186 187 188 |
# File 'lib/moped/session.rb', line 180 def new( = {}) session = with() session.instance_variable_set(:@cluster, cluster.dup) if block_given? yield session else session end end |
#safe? ⇒ true, false
Is the session operating in safe mode?
199 200 201 |
# File 'lib/moped/session.rb', line 199 def safe? !!safety end |
#safety ⇒ Boolean, Hash
Get the safety level for the session.
211 212 213 |
# File 'lib/moped/session.rb', line 211 def safety [:safe]. end |
#use(database) ⇒ Object
Switch the session’s current database.
224 225 226 227 |
# File 'lib/moped/session.rb', line 224 def use(database) [:database] = database set_current_database database end |