Class: Insulin::MongoHandle
- Inherits:
-
Object
- Object
- Insulin::MongoHandle
- Defined in:
- lib/insulin/mongo_handle.rb
Overview
This class is a simple wrapper around a MongoDB connection
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
-
#drop_db ⇒ Object
Drop this database.
-
#initialize(conf) ⇒ MongoHandle
constructor
Set up the connection as described by ‘conf’.
Constructor Details
#initialize(conf) ⇒ MongoHandle
Set up the connection as described by ‘conf’
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/insulin/mongo_handle.rb', line 12 def initialize conf @conf = conf begin @connection = Mongo::Connection.new @db = @connection.db @conf["database"] rescue Mongo::ConnectionFailure puts "MongoDB doesn't appear to be running. We can't go on without this" exit 1 end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/insulin/mongo_handle.rb', line 9 def connection @connection end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
9 10 11 |
# File 'lib/insulin/mongo_handle.rb', line 9 def db @db end |
Instance Method Details
#drop_db ⇒ Object
Drop this database
24 25 26 |
# File 'lib/insulin/mongo_handle.rb', line 24 def drop_db @connection.drop_database @conf["database"] end |