Class: Mobility::Backends::Sequel::Table
- Inherits:
-
Object
- Object
- Mobility::Backends::Sequel::Table
- Includes:
- Mobility::Backends::Sequel, Table
- Defined in:
- lib/mobility/backends/sequel/table.rb
Overview
Implements the Table backend for Sequel models.
Defined Under Namespace
Modules: Cache, Translation Classes: CacheRequired
Backend Configuration collapse
Class Method Summary collapse
- .build_op(attr, locale) ⇒ Sequel::SQL::QualifiedIdentifier
-
.prepare_dataset(dataset, predicate, locale) ⇒ Sequel::Dataset
Prepared dataset.
-
.translation_class ⇒ Symbol
Class for translations.
Instance Method Summary collapse
Methods included from Table
#association_name, #each_locale, #foreign_key, #read, #subclass_name, #table_name, #write
Methods included from Mobility::Backends::Sequel
Class Method Details
.build_op(attr, locale) ⇒ Sequel::SQL::QualifiedIdentifier
51 52 53 |
# File 'lib/mobility/backends/sequel/table.rb', line 51 def build_op(attr, locale) ::Sequel::SQL::QualifiedIdentifier.new(table_alias(locale), attr || :value) end |
.configure(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mobility/backends/sequel/table.rb', line 33 def configure() raise CacheRequired, "Cache required for Sequel::Table backend" if [:cache] == false table_name = Util.singularize(model_class.table_name) [:table_name] ||= :"#{table_name}_translations" [:foreign_key] ||= Util.foreign_key(Util.camelize(table_name.downcase)) if association_name = [:association_name] [:subclass_name] ||= Util.camelize(Util.singularize(association_name)) else [:association_name] = :translations [:subclass_name] ||= :Translation end %i[table_name foreign_key association_name subclass_name].each { |key| [key] = [key].to_sym } end |
.prepare_dataset(dataset, predicate, locale) ⇒ Sequel::Dataset
Returns Prepared dataset.
59 60 61 |
# File 'lib/mobility/backends/sequel/table.rb', line 59 def prepare_dataset(dataset, predicate, locale) join_translations(dataset, locale, visit(predicate, locale)) end |
.translation_class ⇒ Symbol
Returns class for translations.
23 24 25 |
# File 'lib/mobility/backends/sequel/table.rb', line 23 def translation_class @translation_class ||= model_class.const_get(subclass_name) end |
Instance Method Details
#translation_class ⇒ Object
17 18 19 |
# File 'lib/mobility/backends/sequel/table.rb', line 17 def translation_class self.class.translation_class end |
#translation_for(locale) ⇒ Object
159 160 161 162 163 |
# File 'lib/mobility/backends/sequel/table.rb', line 159 def translation_for(locale, **) translation = model.send(association_name).find { |t| t.locale == locale.to_s } translation ||= translation_class.new(locale: locale) translation end |