Class: CouchI18n::Store
- Inherits:
-
Object
- Object
- CouchI18n::Store
- Defined in:
- lib/couch_i18n/store.rb
Instance Method Summary collapse
-
#[](key, options = {}) ⇒ Object
alias for read.
-
#[]=(key, value, options = {}) ⇒ Object
Now the store features.
- #available_locales ⇒ Object
- #get_couchrest_name ⇒ Object
- #keys ⇒ Object
- #set_couchrest_name(name) ⇒ Object
Instance Method Details
#[](key, options = {}) ⇒ Object
alias for read
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/couch_i18n/store.rb', line 18 def [](key, = {}) key = key.to_s.gsub('/', '.') Rails.cache.fetch("couch_i18n-#{key}") do old_database_name = get_couchrest_name begin set_couchrest_name CouchPotato::Config.database_name # Set database to original configured name translation = CouchI18n::Translation.find_by_key(key.to_s) translation ||= CouchI18n::Translation.create(:key => key, :value => [:default].presence || key.to_s.split('.').last, :translated => false) ensure set_couchrest_name old_database_name end translation.value end end |
#[]=(key, value, options = {}) ⇒ Object
Now the store features
9 10 11 12 13 14 15 |
# File 'lib/couch_i18n/store.rb', line 9 def []=(key, value, = {}) key = key.to_s.gsub('/', '.') existing = CouchI18n::Translation.find_by_key(key) rescue nil translation = existing || CouchI18n::Translation.new(:key => key) translation.value = value translation.save end |
#available_locales ⇒ Object
4 5 6 |
# File 'lib/couch_i18n/store.rb', line 4 def available_locales CouchI18n::Translation.get_keys_by_level(0) end |
#get_couchrest_name ⇒ Object
41 42 43 |
# File 'lib/couch_i18n/store.rb', line 41 def get_couchrest_name CouchPotato.database.couchrest_database.name end |
#keys ⇒ Object
45 46 47 |
# File 'lib/couch_i18n/store.rb', line 45 def keys CouchI18n::Translation.all.map(&:key) end |
#set_couchrest_name(name) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/couch_i18n/store.rb', line 33 def set_couchrest_name(name) d = CouchPotato.database.couchrest_database d.instance_variable_set('@name', name) d.instance_variable_set('@uri', "/#{name.gsub('/', '%2F')}") d.instance_variable_set('@bulk_save_cache', []) d.instance_variable_set('@root', d.host + d.uri) end |