Class: I18n::Backend::Mongodb
- Inherits:
-
Object
- Object
- I18n::Backend::Mongodb
- Includes:
- Base, Flatten
- Defined in:
- lib/i18n/backend/mongodb.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#initialize(collection, subtrees = true) ⇒ Mongodb
constructor
A new instance of Mongodb.
- #store_translations(locale, data, options = {}) ⇒ Object
Constructor Details
#initialize(collection, subtrees = true) ⇒ Mongodb
Returns a new instance of Mongodb.
10 11 12 13 |
# File 'lib/i18n/backend/mongodb.rb', line 10 def initialize(collection, subtrees = true) @collection, @subtrees = collection, subtrees collection.indexes.create({key: 1, locale: 1}, {unique: true}) end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
8 9 10 |
# File 'lib/i18n/backend/mongodb.rb', line 8 def collection @collection end |
Instance Method Details
#available_locales ⇒ Object
22 23 24 |
# File 'lib/i18n/backend/mongodb.rb', line 22 def available_locales collection.find.distinct(:locale).map(&:to_sym) end |
#store_translations(locale, data, options = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/i18n/backend/mongodb.rb', line 15 def store_translations(locale, data, ={}) escape = .fetch(:escape, true) flatten_translations(locale, data, escape, @subtrees).each do |key, value| collection.find(key: key.to_s, locale: locale.to_s).upsert('$set' => { value: value }) end end |