-
Notifications
You must be signed in to change notification settings - Fork 10
/
manager.rb
32 lines (27 loc) · 903 Bytes
/
manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module EmbeddedMongo::Backend
class Manager
def initialize(spec)
@spec = spec
@dbs = {}
end
def insert_documents(db_name, collection_name, documents)
EmbeddedMongo.log.info("INSERT: #{db_name.inspect} #{collection_name.inspect} #{documents.inspect}")
collection = get_collection(db_name, collection_name)
collection.insert_documents(documents)
end
def find(db_name, collection_name, selector)
EmbeddedMongo.log.info("FIND: #{db_name.inspect} #{collection_name.inspect} #{selector.inspect}")
collection = get_collection(db_name, collection_name)
collection.find(selector)
end
private
def get_db(db_name)
@dbs[db_name] ||= DB.new(db_name)
end
def get_collection(db_name, collection_name)
db = get_db(db_name)
collection = db.get_collection(collection_name)
collection
end
end
end