class Sinatra::Monk::MBase
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.
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.
Attributes
Public Class Methods
(Ruby 2.x) Setup the Monk
with the data that was sent. Autoconnect if :connect flag is true. @param user [String] the database username, @param pass [String] the password of the previous database user, @param database [String] the name of the database, @param host [String] the host of the database, @param port [Fixnum] the port to connect to the database, @param opts [Hash] monk options (set :conect to autoconnect the Monk
)
# 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
Public Instance Methods
Aliased initialize method, made to add Ruby 2.0 version.
Closes the connection with the server, you MAY NOT TRY to alter the collection while in that state.
# File lib/sinatra-monk/monk.rb, line 60 def close @client.close end
Conects the Monk
to Mongo. @param user [String] the database username, @param pass [String] the password of the previous database user.
# 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
Returns the Monk
connection state.
# File lib/sinatra-monk/monk.rb, line 65 def connected? return @client.connected? end