Class: Mobility::Backends::Sequel::Table
Overview
Implements the Table backend for Sequel models.
Defined Under Namespace
Modules: Cache, Translation
Classes: CacheRequired
Backend Configuration
collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Table
#association_name, #each_locale, #foreign_key, #read, #subclass_name, #table_name, #write
included
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
|
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/mobility/backends/sequel/table.rb', line 33
def configure(options)
raise CacheRequired, "Cache required for Sequel::Table backend" if options[:cache] == false
table_name = Util.singularize(model_class.table_name)
options[:table_name] ||= :"#{table_name}_translations"
options[:foreign_key] ||= Util.foreign_key(Util.camelize(table_name.downcase))
if association_name = options[:association_name]
options[:subclass_name] ||= Util.camelize(Util.singularize(association_name))
else
options[:association_name] = :translations
options[:subclass_name] ||= :Translation
end
i[table_name foreign_key association_name subclass_name].each { |key| options[key] = options[key].to_sym }
end
|
.prepare_dataset(dataset, predicate, locale) ⇒ Sequel::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
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
|