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

client[R]
database[R]
password[R]
username[R]

Public Class Methods

new(user:'', pass:'', database:'local', host:'localhost', port:27017, opts:{:connect => false}) click to toggle source

(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
Also aliased as: _ol_initialize

Public Instance Methods

_ol_initialize(user:'', pass:'', database:'local', host:'localhost', port:27017, opts:{:connect => false})

Aliased initialize method, made to add Ruby 2.0 version.

Alias for: new
close() click to toggle source

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
connect(user = @username, pass = @password) click to toggle source

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
connected?() click to toggle source

Returns the Monk connection state.

# File lib/sinatra-monk/monk.rb, line 65
def connected?
  return @client.connected?
end