Class: UsageTracker::Adapters::Mongodb
- Inherits:
-
Object
- Object
- UsageTracker::Adapters::Mongodb
- Defined in:
- lib/usage_tracker/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 |
# File 'lib/usage_tracker/adapters/mongodb.rb', line 9 def initialize (settings) @database = db = Mongo::Connection.new(settings.database['host'], settings.database['port']).db(settings.database['name']) @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/adapters/mongodb.rb', line 8 def database @database end |
Instance Method Details
#save_doc(doc) ⇒ Object
18 19 20 |
# File 'lib/usage_tracker/adapters/mongodb.rb', line 18 def save_doc(doc) @collection.insert(doc) end |