Module: Mobility::Backends::HashValued
- Included in:
- ActiveRecord::PgHash, ActiveRecord::Serialized, Sequel::PgHash, Sequel::Serialized
- Defined in:
- lib/mobility/backends/hash_valued.rb
Overview
Defines read and write methods that access the value at a key with value locale
on a translations
hash.
Backend Accessors collapse
-
#read(locale, _ = {}) ⇒ Object
Gets the translated value for provided locale from configured backend.
-
#write(locale, value, _ = {}) ⇒ Object
Updates translation for provided locale without calling backend’s methods to persist the changes.
Instance Method Summary collapse
-
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
Instance Method Details
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
24 25 26 |
# File 'lib/mobility/backends/hash_valued.rb', line 24 def each_locale translations.each { |l, _| yield l } end |
#read(locale, _ = {}) ⇒ Object
Gets the translated value for provided locale from configured backend.
13 14 15 |
# File 'lib/mobility/backends/hash_valued.rb', line 13 def read(locale, _ = {}) translations[locale] end |
#write(locale, value, _ = {}) ⇒ Object
Updates translation for provided locale without calling backend’s methods to persist the changes.
18 19 20 |
# File 'lib/mobility/backends/hash_valued.rb', line 18 def write(locale, value, _ = {}) translations[locale] = value end |