Class: Mobility::Backends::Sequel::Container
- Inherits:
-
Object
- Object
- Mobility::Backends::Sequel::Container
- Includes:
- Container, Mobility::Backends::Sequel
- Defined in:
- lib/mobility/backends/sequel/container.rb
Overview
Implements the Container backend for Sequel models.
Defined Under Namespace
Classes: InvalidColumnType, JSONBOp, JSONOp
Backend Accessors collapse
-
#read(locale, _ = nil) ⇒ String, ...
Value of translation.
-
#write(locale, value, _ = nil) ⇒ String, ...
Updated value.
Backend Configuration collapse
Instance Method Summary collapse
-
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
Methods included from Container
Methods included from Mobility::Backends::Sequel
Class Method Details
.configure(options) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/mobility/backends/sequel/container.rb', line 42 def self.configure() [:column_name] ||= :translations [:column_name] = [:column_name].to_sym column_name, db_schema = [:column_name], model_class.db_schema [:column_type] = db_schema[column_name] && (db_schema[column_name][:db_type]).to_sym unless %i[json jsonb].include?([:column_type]) raise InvalidColumnType, "#{[:column_name]} must be a column of type json or jsonb" end end |
Instance Method Details
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
54 55 56 57 58 |
# File 'lib/mobility/backends/sequel/container.rb', line 54 def each_locale model[column_name].each do |l, _| yield l.to_sym unless read(l).nil? end end |
#read(locale, _ = nil) ⇒ String, ...
Note:
Translation may be a string, integer, boolean, hash or array since value is stored on a JSON hash.
Returns Value of translation.
24 25 26 |
# File 'lib/mobility/backends/sequel/container.rb', line 24 def read(locale, _ = nil) model_translations(locale)[attribute] end |
#write(locale, value, _ = nil) ⇒ String, ...
Note:
Translation may be a string, integer, boolean, hash or array since value is stored on a JSON hash.
Returns Updated value.
34 35 36 37 |
# File 'lib/mobility/backends/sequel/container.rb', line 34 def write(locale, value, _ = nil) set_attribute_translation(locale, value) model_translations(locale)[attribute] end |