Class: DataStore

Inherits:
Object show all
Defined in:
app/volt/tasks/live_query/data_store.rb

Instance Method Summary collapse

Constructor Details

#initializeDataStore

Returns a new instance of DataStore.



4
5
6
7
# File 'app/volt/tasks/live_query/data_store.rb', line 4

def initialize
  @@mongo_db ||= Mongo::MongoClient.new("localhost", 27017)
  @@db ||= @@mongo_db.db("development")
end

Instance Method Details

#query(collection, query) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/volt/tasks/live_query/data_store.rb', line 9

def query(collection, query)
  puts "QUERY: #{collection} - #{query.inspect}"

  query = query.dup
  query.keys.each do |key|
    if key =~ /_id$/
      query[key] = BSON::ObjectId(query[key])
    end
  end

  @@db[collection].find(query).to_a
end