Class: Mobility::Backend::KeyValue::TranslationsCache
- Defined in:
- lib/mobility/backend/key_value.rb
Overview
Simple cache to memoize translations as a hash so they can be fetched quickly.
Instance Method Summary collapse
- #[](locale) ⇒ Object
- #[]=(locale, value) ⇒ Object
- #each_translation {|locale, translation| ... } ⇒ Object
- #initialize(backend) ⇒ TranslationsCache constructor
Constructor Details
#initialize(backend) ⇒ TranslationsCache
49 50 51 |
# File 'lib/mobility/backend/key_value.rb', line 49 def initialize(backend) @cache = Hash.new { |hash, locale| hash[locale] = backend.translation_for(locale) } end |
Instance Method Details
#[](locale) ⇒ Object
54 55 56 |
# File 'lib/mobility/backend/key_value.rb', line 54 def [](locale) @cache[locale].value end |
#[]=(locale, value) ⇒ Object
60 61 62 |
# File 'lib/mobility/backend/key_value.rb', line 60 def []=(locale, value) @cache[locale].value = value end |
#each_translation {|locale, translation| ... } ⇒ Object
65 66 67 |
# File 'lib/mobility/backend/key_value.rb', line 65 def each_translation &block @cache.each_value &block end |