Class: GoTranslateYourself::MongoStore
- Inherits:
-
BaseStore
- Object
- BaseStore
- GoTranslateYourself::MongoStore
show all
- Defined in:
- app/modles/go_translate_yourself/mongo_store.rb
Instance Method Summary
collapse
Methods inherited from BaseStore
#default_translation, #keys, #keys_without_prefix
Constructor Details
#initialize(collection) ⇒ MongoStore
Returns a new instance of MongoStore.
3
4
5
|
# File 'app/modles/go_translate_yourself/mongo_store.rb', line 3
def initialize(collection)
@collection = collection
end
|
Instance Method Details
#[](key) ⇒ Object
11
12
13
14
15
16
17
|
# File 'app/modles/go_translate_yourself/mongo_store.rb', line 11
def [](key)
if document = collection.find_one(_id: key)
document["value"]
else
default_translation(key)
end
end
|
#[]=(key, value) ⇒ Object
7
8
9
|
# File 'app/modles/go_translate_yourself/mongo_store.rb', line 7
def []=(key, value)
collection.update({_id: key}, {'$set' => {:value => value}}, upsert: true, safe: true)
end
|
#clear_database ⇒ Object
19
20
21
|
# File 'app/modles/go_translate_yourself/mongo_store.rb', line 19
def clear_database
collection.drop
end
|