Class: Mobility::Backends::Sequel::Table
- Inherits:
-
Object
- Object
- Mobility::Backends::Sequel::Table
- Includes:
- Mobility::Backends::Sequel, Table, Util
- Defined in:
- lib/mobility/backends/sequel/table.rb
Overview
Implements the Table backend for Sequel models.
Defined Under Namespace
Modules: Cache Classes: CacheRequired, QueryMethods
Constant Summary
Constants included from Util
Util::VALID_CONSTANT_NAME_REGEXP
Instance Attribute Summary collapse
-
#translation_class ⇒ Symbol
readonly
Class for translations.
Attributes included from Table
Backend Configuration collapse
Instance Method Summary collapse
-
#initialize(model, attribute, options = {}) ⇒ Table
constructor
A new instance of Table.
- #translation_for(locale, _) ⇒ Object
Methods included from Util
#blank?, #camelize, #constantize, #demodulize, #foreign_key, included, #presence, #present?, #singularize, #underscore
Methods included from Table
Methods included from Mobility::Backend::OrmDelegator
Methods included from Mobility::Backends::Sequel
included, #setup_query_methods
Constructor Details
#initialize(model, attribute, options = {}) ⇒ Table
Returns a new instance of Table.
24 25 26 27 |
# File 'lib/mobility/backends/sequel/table.rb', line 24 def initialize(model, attribute, = {}) super @translation_class = [:model_class].const_get([:subclass_name]) end |
Instance Attribute Details
#translation_class ⇒ Symbol (readonly)
Returns class for translations.
21 22 23 |
# File 'lib/mobility/backends/sequel/table.rb', line 21 def translation_class @translation_class end |
Class Method Details
.configure(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mobility/backends/sequel/table.rb', line 35 def self.configure() raise CacheRequired, "Cache required for Sequel::Table backend" if [:cache] == false table_name = [:model_class].table_name [:table_name] ||= :"#{singularize(table_name)}_translations" [:foreign_key] ||= foreign_key(camelize(singularize(table_name.to_s.downcase))) if association_name = [:association_name] [:subclass_name] ||= camelize(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 |
Instance Method Details
#translation_for(locale, _) ⇒ Object
91 92 93 94 95 |
# File 'lib/mobility/backends/sequel/table.rb', line 91 def translation_for(locale, _) translation = model.send(association_name).find { |t| t.locale == locale.to_s } translation ||= translation_class.new(locale: locale) translation end |