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

Instance Method Summary collapse

Instance Method Details

#each_locale {|Locale| ... } ⇒ Object

Yields locales available for this attribute.

Yield Parameters:

  • Locale (Symbol)


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.

Parameters:

  • locale (Symbol)

    Locale to read

Returns:

  • (Object)

    Value of translation



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.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

Returns:

  • (Object)

    Updated value



18
19
20
# File 'lib/mobility/backends/hash_valued.rb', line 18

def write(locale, value, _ = {})
  translations[locale] = value
end