Class: Mobility::Backend::ActiveRecord::HashValued

Inherits:
Object
  • Object
show all
Includes:
Mobility::Backend
Defined in:
lib/mobility/backend/active_record/hash_valued.rb

Overview

Internal class used by ActiveRecord backends that store values as a hash.

Direct Known Subclasses

Hstore, Jsonb

Defined Under Namespace

Classes: Coder

Instance Attribute Summary

Attributes included from Mobility::Backend

#attribute, #model, #options

Backend Accessors collapse

Instance Method Summary collapse

Methods included from Mobility::Backend

included, #initialize, method_name

Instance Method Details

#read(locale, **options) ⇒ Object

Returns Value of translation.

Parameters:

  • locale (Symbol)

    Locale to read

  • options (Hash)

Returns:

  • (Object)

    Value of translation



14
15
16
# File 'lib/mobility/backend/active_record/hash_valued.rb', line 14

def read(locale, **options)
  translations[locale]
end

#translationsObject Also known as: new_cache



24
25
26
# File 'lib/mobility/backend/active_record/hash_valued.rb', line 24

def translations
  model.read_attribute(attribute)
end

#write(locale, value, **options) ⇒ Object

Returns Updated value.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

  • options (Hash)

Returns:



19
20
21
# File 'lib/mobility/backend/active_record/hash_valued.rb', line 19

def write(locale, value, **options)
  translations[locale] = value
end

#write_to_cache?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mobility/backend/active_record/hash_valued.rb', line 29

def write_to_cache?
  true
end