Sha256: f9dd4e234a56f6de4a75a885af725cbbaaf798c5d434af9a6078e63ec9d14ead
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
require 'tmpdir' module IsolatedServer class Mongodb < Base attr_reader :dbpath, :port, :repl_set def initialize(options = {}) super options @dbpath = FileUtils.mkdir("#{@base}/data").first end def boot! @port ||= grab_free_port up! end def up! mongod = locate_executable("mongod") exec_server([ mongod, '--dbpath', @dbpath, '--port', @port, *@params ].shelljoin) until up? sleep(0.1) end end def up? begin connection.ping true rescue Mongo::ConnectionFailure false end end def connection @connection ||= connection_klass.new('localhost', @port) end def connection_klass if Kernel.const_defined?("Mongo::MongoClient") # 1.8.0+ Mongo::MongoClient else # < 1.8.0 Mongo::Connection end end def console system(['mongo', '--port', @port].shelljoin) end end end
Version data entries
4 entries across 4 versions & 1 rubygems