Class: Kymera::MongoDriver

Inherits:
Object
  • Object
show all
Includes:
Mongo
Defined in:
lib/kymera/mongo_driver.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address = "localhost", port = 27017, database = 'default_db', collection = 'default_db') ⇒ MongoDriver

This can be initialized by specifying the address and the port of the mongodb server. By default, this expects that the mongodb server is located on the same machine as the calling code. A collection name will also be defaulted if not passed in. By default, this will be ‘default_db’



20
21
22
23
24
25
# File 'lib/kymera/mongo_driver.rb', line 20

def initialize(address = "localhost", port = 27017, database = 'default_db', collection = 'default_db')
  puts "Initializing db connection.."
  @db_client = MongoClient.new(address, port).db(database)
  puts "Assigning collection..."
  @collection = collection
end

Class Method Details

.log_results(log, address = "localhost", port = 27017, database = 'default_db', collection = 'default_collection') ⇒ Object



11
12
13
14
# File 'lib/kymera/mongo_driver.rb', line 11

def self.log_results(log, address = "localhost", port = 27017, database = 'default_db', collection = 'default_collection')
  puts "Sending results to mongodb..."
  MongoDriver.new(address, port, database, collection).write_log(log)
end

Instance Method Details

#write_log(log) ⇒ Object

The @param log needs to be a JSON string.



29
30
31
32
33
34
35
# File 'lib/kymera/mongo_driver.rb', line 29

def write_log(log)
  puts "Getting collection..."
  coll = @db_client["#{@collection}"]
  puts "Sending insert request.."
  coll.insert(JSON.parse log)
  puts "Request completed"
end