Class: MinceMongoDb::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mince_mongo_db/connection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



19
20
21
# File 'lib/mince_mongo_db/connection.rb', line 19

def initialize
  self.connection = Mongo::Connection.new(Config.database_host)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



9
10
11
# File 'lib/mince_mongo_db/connection.rb', line 9

def connection
  @connection
end

#dbObject

Returns the value of attribute db.



9
10
11
# File 'lib/mince_mongo_db/connection.rb', line 9

def db
  @db
end

Class Method Details

.connectionObject



11
12
13
# File 'lib/mince_mongo_db/connection.rb', line 11

def self.connection
  instance.connection
end

.dbObject



15
16
17
# File 'lib/mince_mongo_db/connection.rb', line 15

def self.db
  instance.db
end

Instance Method Details

#authObject



29
30
31
# File 'lib/mince_mongo_db/connection.rb', line 29

def auth
  db.authenticate(Config.username, Config.password) if auth_provided?
end

#auth_provided?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mince_mongo_db/connection.rb', line 33

def auth_provided?
  !!Config.username && !!Config.password
end

#database_nameObject



37
38
39
# File 'lib/mince_mongo_db/connection.rb', line 37

def database_name
  Config.database_name
end