Class: Mobility::Backend::Sequel::Serialized
- Includes:
- Mobility::Backend
- Defined in:
- lib/mobility/backend/sequel/serialized.rb
Overview
Implements Mobility::Backend::Serialized backend for Sequel models, using the Sequel serialization plugin.
Defined Under Namespace
Modules: SerializationModificationDetectionFix 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
Instance Method Summary collapse
-
#translations ⇒ Hash
Returns deserialized column value.
Methods included from Mobility::Backend
included, #initialize, method_name
Class Method Details
.configure!(options) ⇒ Object
51 52 53 54 55 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 51 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
#new_cache ⇒ Hash
102 103 104 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 102 def new_cache translations end |
#read(locale, **options) ⇒ Object
Returns Value of translation.
38 39 40 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 38 def read(locale, **) translations[locale] end |
#translations ⇒ Hash
Returns deserialized column value
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 89 def translations _attribute = attribute.to_sym if model.deserialized_values.has_key?(_attribute) model.deserialized_values[_attribute] elsif model.frozen? deserialize_value(_attribute, serialized_value) else model.deserialized_values[_attribute] = deserialize_value(_attribute, serialized_value) end end |
#write(locale, value, **options) ⇒ Object
Returns Value of translation.
43 44 45 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 43 def write(locale, value, **) translations[locale] = value end |
#write_to_cache? ⇒ Boolean
107 108 109 |
# File 'lib/mobility/backend/sequel/serialized.rb', line 107 def write_to_cache? true end |