Class: UsageTrackerServer::Adapters::Mongodb
- Inherits:
-
Object
- Object
- UsageTrackerServer::Adapters::Mongodb
- Defined in:
- lib/usage_tracker_server/adapters/mongodb.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
Instance Method Summary collapse
-
#initialize(settings) ⇒ Mongodb
constructor
A new instance of Mongodb.
- #save_doc(doc) ⇒ Object
Constructor Details
#initialize(settings) ⇒ Mongodb
Returns a new instance of Mongodb.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/usage_tracker_server/adapters/mongodb.rb', line 9 def initialize (settings) @database = db = Mongo::Connection.new(settings.database['host'], settings.database['port']).db(settings.database['name']) if settings.database['username'] || settings.database['password'] db.authenticate(settings.database['username'], settings.database['password']) end @collection = db[settings.database['collection']] db rescue Errno::ECONNREFUSED, Mongo::ConnectionError => e raise "Unable to connect to database #{settings.database['name']} with #{settings.adapter} adapter: #{e.}" end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
8 9 10 |
# File 'lib/usage_tracker_server/adapters/mongodb.rb', line 8 def database @database end |
Instance Method Details
#save_doc(doc) ⇒ Object
23 24 25 |
# File 'lib/usage_tracker_server/adapters/mongodb.rb', line 23 def save_doc(doc) @collection.insert(doc) end |