Class: Translator::MongoStore

Inherits:
Object
  • Object
show all
Defined in:
app/backends/translator/mongo_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ MongoStore


3
4
5
# File 'app/backends/translator/mongo_store.rb', line 3

def initialize(collection)
  @collection = collection
end

Instance Method Details

#[](key) ⇒ Object


18
19
20
21
22
23
24
# File 'app/backends/translator/mongo_store.rb', line 18

def [](key)
  if document = collection.find_one(:_id => key)
    document["value"]
  else
    nil
  end
end

#[]=(key, value) ⇒ Object


11
12
13
14
15
16
# File 'app/backends/translator/mongo_store.rb', line 11

def []=(key, value)
  value = nil if value == '' || value.nil?
  collection.update({:_id => key},
                    {'$set' => {:value => ActiveSupport::JSON.encode(value)}},
                    {:upsert => true, :safe => true})
end

#clear_databaseObject


34
35
36
# File 'app/backends/translator/mongo_store.rb', line 34

def clear_database
  collection.drop
end

#destroy_entry(key) ⇒ Object


26
27
28
# File 'app/backends/translator/mongo_store.rb', line 26

def destroy_entry(key)
  @collection.remove({:_id => key})
end

#keysObject


7
8
9
# File 'app/backends/translator/mongo_store.rb', line 7

def keys
  @collection.distinct :_id
end

#searchable?Boolean


30
31
32
# File 'app/backends/translator/mongo_store.rb', line 30

def searchable?
  true
end