Class: Mobility::Backends::Hash

Inherits:
Object
  • Object
show all
Includes:
Mobility::Backend
Defined in:
lib/mobility/backends/hash.rb

Overview

Backend which stores translations in an in-memory hash.

Instance Attribute Summary

Attributes included from Mobility::Backend

#attribute, #model

Backend Accessors collapse

Instance Method Summary collapse

Methods included from Mobility::Backend

#==, #each, included, #initialize, #locales, #model_class, #options, #present?

Instance Method Details

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

Yields locales available for this attribute.

Yield Parameters:

  • Locale (Symbol)


26
27
28
# File 'lib/mobility/backends/hash.rb', line 26

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

  • (Object)


14
15
16
# File 'lib/mobility/backends/hash.rb', line 14

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

  • (Object)


20
21
22
# File 'lib/mobility/backends/hash.rb', line 20

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