Class: Mobility::Backends::ActiveRecord::KeyValue
- Inherits:
-
Object
- Object
- Mobility::Backends::ActiveRecord::KeyValue
- Includes:
- Mobility::Backends::ActiveRecord, KeyValue
- Defined in:
- lib/mobility/backends/active_record/key_value.rb
Overview
Implements the KeyValue backend for ActiveRecord models.
Defined Under Namespace
Classes: QueryMethods
Instance Attribute Summary
Attributes included from KeyValue
Backend Configuration collapse
Instance Method Summary collapse
-
#translation_for(locale, _options = {}) ⇒ Mobility::ActiveRecord::TextTranslation, Mobility::ActiveRecord::StringTranslation
Returns translation for a given locale, or builds one if none is present.
Methods included from KeyValue
#each_locale, #initialize, #read, #write
Methods included from Mobility::Backend::OrmDelegator
Methods included from Mobility::Backends::ActiveRecord
included, #setup_query_methods
Class Method Details
.configure(options) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/mobility/backends/active_record/key_value.rb', line 38 def self.configure() super type = [:type] [:class_name] ||= Mobility::ActiveRecord.const_get("#{type.capitalize}Translation".freeze) [:class_name] = [:class_name].constantize if [:class_name].is_a?(String) [:association_name] ||= :"#{options[:type]}_translations" i[type association_name].each { |key| [key] = [key].to_sym } end |
Instance Method Details
#translation_for(locale, _options = {}) ⇒ Mobility::ActiveRecord::TextTranslation, Mobility::ActiveRecord::StringTranslation
Returns translation for a given locale, or builds one if none is present.
89 90 91 92 93 |
# File 'lib/mobility/backends/active_record/key_value.rb', line 89 def translation_for(locale, = {}) translation = translations.find { |t| t.key == attribute && t.locale == locale.to_s } translation ||= translations.build(locale: locale, key: attribute) translation end |