Class: Sinatra::Monk::MBase
- Inherits:
-
Object
- Object
- Sinatra::Monk::MBase
- Defined in:
- lib/sinatra-monk/2.0.rb,
lib/sinatra-monk/monk.rb
Overview
Provides a base class for Mongo database management. This is the simplest way to connect to Mongo with Monk. It is intented to keep Sinatra’s philosofy of keeping it as simple as possible for use.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#_ol_initialize ⇒ Object
Aliased initialize method, made to add Ruby 2.0 version.
-
#close ⇒ Object
Closes the connection with the server, you MAY NOT TRY to alter the collection while in that state.
-
#connect(user = @username, pass = @password) ⇒ Object
Conects the Monk to Mongo.
-
#connected? ⇒ Boolean
Returns the Monk connection state.
-
#initialize(user = '', pass = '', database = 'local', host = 'localhost', port = 27017, opts = {:connect => false}) ⇒ MBase
constructor
(Any Ruby) Setup the Monk with the data that was sent.
Constructor Details
#initialize(user = '', pass = '', database = 'local', host = 'localhost', port = 27017, opts = {:connect => false}) ⇒ MBase
(Any Ruby) Setup the Monk with the data that was sent. Autoconnect if :connect flag is true.
47 48 49 50 |
# File 'lib/sinatra-monk/2.0.rb', line 47 def initialize(user:'', pass:'', database:'local', host:'localhost', port:27017, opts:{:connect => false}) _ol_initialize(user, pass, database, host, port, opts) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
34 35 36 |
# File 'lib/sinatra-monk/monk.rb', line 34 def client @client end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
34 35 36 |
# File 'lib/sinatra-monk/monk.rb', line 34 def database @database end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
34 35 36 |
# File 'lib/sinatra-monk/monk.rb', line 34 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
34 35 36 |
# File 'lib/sinatra-monk/monk.rb', line 34 def username @username end |
Instance Method Details
#_ol_initialize ⇒ Object
Aliased initialize method, made to add Ruby 2.0 version.
37 |
# File 'lib/sinatra-monk/2.0.rb', line 37 alias _ol_initialize initialize |
#close ⇒ Object
Closes the connection with the server, you MAY NOT TRY to alter the collection while in that state.
60 61 62 |
# File 'lib/sinatra-monk/monk.rb', line 60 def close @client.close end |
#connect(user = @username, pass = @password) ⇒ Object
Conects the Monk to Mongo.
72 73 74 75 76 77 78 |
# File 'lib/sinatra-monk/monk.rb', line 72 def connect user = @username, pass = @password return true if connected? @client.connect @username = user @password = pass return @database.authenticate @username, @password end |
#connected? ⇒ Boolean
Returns the Monk connection state.
65 66 67 |
# File 'lib/sinatra-monk/monk.rb', line 65 def connected? return @client.connected? end |