Sha256: e2f053fcc174418486c7fee16aa93592c693349c2292da958656490eceacbffc
Contents?: true
Size: 1.4 KB
Versions: 3
Compression:
Stored size: 1.4 KB
Contents
module Mobility module Backend =begin Stores translated attribute as a column on the model table. To use this backend, ensure that the model table has columns named +<attribute>_<locale>+ for every locale in +I18n.available_locales+. ==Backend Options There are no options for this backend. Also, the +locale_accessors+ option will be ignored if set, since it would cause a conflict with column accessors. @see Mobility::Backend::ActiveRecord::Column @see Mobility::Backend::Sequel::Column =end module Column include OrmDelegator # @!group Backend Accessors # # @!macro backend_reader def read(locale, **_) model.send(column(locale)) end # @!macro backend_writer def write(locale, value, **_) model.send("#{column(locale)}=", value) end # @!endgroup # Returns name of column where translated attribute is stored # @param [Symbol] locale # @return [String] def column(locale = Mobility.locale) Column.column_name_for(attribute, locale) end # Returns name of column where translated attribute is stored # @param [String] attribute # @param [Symbol] locale # @return [String] def self.column_name_for(attribute, locale = Mobility.locale) normalized_locale = Mobility.normalize_locale(locale) "#{attribute}_#{normalized_locale}".to_sym end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mobility-0.1.10 | lib/mobility/backend/column.rb |
mobility-0.1.7 | lib/mobility/backend/column.rb |
mobility-0.1.6 | lib/mobility/backend/column.rb |