Class: Mobility::Backend::Sequel::Table
- Includes:
- Mobility::Backend
- Defined in:
- lib/mobility/backend/sequel/table.rb
Overview
Implements the Table backend for Sequel models.
Defined Under Namespace
Classes: CacheRequired, QueryMethods
Instance Attribute Summary collapse
-
#association_name ⇒ Symbol
readonly
Name of the association method.
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
-
#initialize(model, attribute, **options) ⇒ Table
constructor
A new instance of Table.
Methods included from Mobility::Backend
Constructor Details
#initialize(model, attribute, **options) ⇒ Table
Returns a new instance of Table.
18 19 20 21 |
# File 'lib/mobility/backend/sequel/table.rb', line 18 def initialize(model, attribute, **) super @association_name = [:association_name] end |
Instance Attribute Details
#association_name ⇒ Symbol (readonly)
Returns name of the association method.
14 15 16 |
# File 'lib/mobility/backend/sequel/table.rb', line 14 def association_name @association_name end |
Class Method Details
.configure!(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mobility/backend/sequel/table.rb', line 40 def self.configure!() raise CacheRequired, "Cache required for Sequel::Table backend" if [:cache] == false table_name = [:model_class].table_name [:table_name] ||= :"#{table_name.to_s.singularize}_translations" [:foreign_key] ||= table_name.to_s.downcase.singularize.camelize.foreign_key if (association_name = [:association_name]).present? [:subclass_name] ||= association_name.to_s.singularize.camelize else [:association_name] = :mobility_model_translations [:subclass_name] ||= :Translation end %i[table_name foreign_key association_name subclass_name].each { |key| [key] = [key].to_sym } end |
Instance Method Details
#clear_cache ⇒ Object
116 117 118 |
# File 'lib/mobility/backend/sequel/table.rb', line 116 def clear_cache model_cache.clear if model_cache end |
#new_cache ⇒ Table::TranslationsCache
106 107 108 109 |
# File 'lib/mobility/backend/sequel/table.rb', line 106 def new_cache reset_model_cache unless model_cache model_cache.for(attribute) end |
#read(locale, **options) ⇒ Object
Returns Value of translation.
25 26 27 |
# File 'lib/mobility/backend/sequel/table.rb', line 25 def read(locale, **) translation_for(locale).send(attribute) end |
#write(locale, value, **options) ⇒ Object
Returns Value of translation.
30 31 32 |
# File 'lib/mobility/backend/sequel/table.rb', line 30 def write(locale, value, **) translation_for(locale).tap { |t| t.send("#{attribute}=", value) }.send(attribute) end |
#write_to_cache? ⇒ Boolean
112 113 114 |
# File 'lib/mobility/backend/sequel/table.rb', line 112 def write_to_cache? true end |