Sha256: ada277afad8a7f0564d0ca38b102c966a44de0806a0a2ad3686269de81e1f845
Contents?: true
Size: 1.14 KB
Versions: 15
Compression:
Stored size: 1.14 KB
Contents
# -*- encoding : utf-8 -*- module Kabutops module Adapters class Mongo < DatabaseAdapter include Extensions::Parameterable params :host, :port, :db, :collection, :user, :password def store result existing = collection.find('id' => result[:id]) if existing.count > 0 existing.each do |document| collection.update({'_id' => document['_id']}, result.to_hash) end else collection.insert(result.to_hash) end end def nested? true end protected def client @@client ||= ::Mongo::MongoClient.new( params[:host] || 'localhost', params[:port] || 27017, ) end def client_db @@client_db ||= client.db(params[:db].to_s || 'kabutops') if params[:user] && params[:password] ok = @@client.authenticate(params[:user], params[:password]) raise 'mongo authentication failed' unless ok end @@client_db end def collection @@collection ||= client_db.collection(params[:collection] || 'kabutops') end end end end
Version data entries
15 entries across 15 versions & 1 rubygems