Class: Mobility::Backend::ActiveRecord::Serialized
- Includes:
- Mobility::Backend
- Defined in:
- lib/mobility/backend/active_record/serialized.rb
Overview
Implements Serialized backend for ActiveRecord models.
Defined Under Namespace
Classes: QueryMethods
Instance Attribute Summary
Attributes included from Mobility::Backend
Backend Accessors collapse
-
#read(locale, **options) ⇒ Object
Value of translation.
-
#write(locale, value, **options) ⇒ Object
Value of translation.
Backend Configuration collapse
Cache Methods collapse
-
#translations ⇒ Hash
(also: #new_cache)
Returns column value as a hash.
- #write_to_cache? ⇒ Boolean
Methods included from Mobility::Backend
included, #initialize, method_name
Class Method Details
.configure!(options) ⇒ Object
44 45 46 47 48 |
# File 'lib/mobility/backend/active_record/serialized.rb', line 44 def self.configure!() [:format] ||= :yaml [:format] = [:format].downcase.to_sym raise ArgumentError, "Serialized backend only supports yaml or json formats." unless [:yaml, :json].include?([:format]) end |
Instance Method Details
#read(locale, **options) ⇒ Object
Returns Value of translation.
31 32 33 |
# File 'lib/mobility/backend/active_record/serialized.rb', line 31 def read(locale, **) translations[locale] end |
#translations ⇒ Hash Also known as: new_cache
Returns column value as a hash
66 67 68 |
# File 'lib/mobility/backend/active_record/serialized.rb', line 66 def translations model.read_attribute(attribute) end |
#write(locale, value, **options) ⇒ Object
Returns Value of translation.
36 37 38 |
# File 'lib/mobility/backend/active_record/serialized.rb', line 36 def write(locale, value, **) translations[locale] = value end |
#write_to_cache? ⇒ Boolean
72 73 74 |
# File 'lib/mobility/backend/active_record/serialized.rb', line 72 def write_to_cache? true end |