Class: MongoI18n::Store
- Inherits:
-
Object
- Object
- MongoI18n::Store
- Defined in:
- lib/mongo-i18n/store.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
-
#[](key, options = nil) ⇒ Object
alias for read.
- #[]=(key, value, options = {}) ⇒ Object
-
#available_locales ⇒ Object
Thankfully borrowed from Jodosha’s redis-store github.com/jodosha/redis-store/blob/master/lib/i18n/backend/redis.rb.
- #del(key) ⇒ Object
-
#initialize(collection, options = {}) ⇒ Store
constructor
A new instance of Store.
- #keys ⇒ Object
Constructor Details
#initialize(collection, options = {}) ⇒ Store
Returns a new instance of Store.
6 7 8 |
# File 'lib/mongo-i18n/store.rb', line 6 def initialize(collection, ={}) @collection, @options = collection, end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
4 5 6 |
# File 'lib/mongo-i18n/store.rb', line 4 def collection @collection end |
Instance Method Details
#[](key, options = nil) ⇒ Object
alias for read
17 18 19 20 21 |
# File 'lib/mongo-i18n/store.rb', line 17 def [](key, =nil) if doc = collection.find_one(:_id => key.to_s) doc["value"].to_s end end |
#[]=(key, value, options = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/mongo-i18n/store.rb', line 10 def []=(key, value, = {}) key = key.to_s doc = {:_id => key, :value => value} collection.save(doc) end |
#available_locales ⇒ Object
Thankfully borrowed from Jodosha’s redis-store github.com/jodosha/redis-store/blob/master/lib/i18n/backend/redis.rb
37 38 39 40 41 42 43 |
# File 'lib/mongo-i18n/store.rb', line 37 def available_locales locales = self.keys.map { |k| k =~ /\./; $` } locales.uniq! locales.compact! locales.map! { |k| k.to_sym } locales end |
#del(key) ⇒ Object
31 32 33 |
# File 'lib/mongo-i18n/store.rb', line 31 def del(key) collection.remove({:_id => key}) end |
#keys ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mongo-i18n/store.rb', line 23 def keys keys = [] collection.find({}, :fields => ["_id"]).each do |row| keys.push(row["_id"]) end keys end |