Module: Jp::Server::MongoConnection

Included in:
Handler, Unlocker
Defined in:
lib/rb/jp/server/mongo_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



4
5
6
# File 'lib/rb/jp/server/mongo_connection.rb', line 4

def database
  @database
end

Instance Method Details

#connect_to_mongo(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rb/jp/server/mongo_connection.rb', line 5

def connect_to_mongo options
  defaults = {
    :mongo_uri            => 'mongodb://localhost',
    :mongo_pool_size      => 10,
    :mongo_pool_timeout   => 60,
  }
  options = defaults.merge(options)
  unless options[:mongo_db]
    raise ArgumentError.new "mongo_db option must be specified"
  end
  # Connect to mongodb
  if options.member? :injected_mongo_database then
    @database = options[:injected_mongo_database]
  else
    connection = Mongo::Connection.from_uri(
      options[:mongo_uri],
      :pool_size => options[:mongo_pool_size],
      :timeout   => options[:mongo_pool_timeout],
    )
    @database = connection.db(options[:mongo_db])
  end
end