module AwesomeHstoreTranslate::ActiveRecord::InstanceMethods
Protected Instance Methods
get_fallback_for_locale(locale)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 37 def get_fallback_for_locale(locale) I18n.fallbacks[locale] if I18n.respond_to?(:fallbacks) end
read_raw_attribute(attr)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 23 def read_raw_attribute(attr) read_attribute(get_column_name(attr)) end
read_translated_attribute(attr, locale = I18n.locale)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 6 def read_translated_attribute(attr, locale = I18n.locale) locales = Array(locale) locales += get_fallback_for_locale(locale) || [] if translation_options[:fallbacks] translations = read_raw_attribute(attr) if translations locales.map(&:to_s).uniq.each do |cur| if translations.has_key?(cur) && !translations[cur].blank? return translations[cur] end end end nil end
write_raw_attribute(attr, value)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 33 def write_raw_attribute(attr, value) write_attribute(get_column_name(attr), value) end
write_translated_attribute(attr, value, locale= I18n.locale)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 27 def write_translated_attribute(attr, value, locale= I18n.locale) translations = read_raw_attribute(attr) || {} translations[locale] = value write_raw_attribute(attr, translations) end
Private Instance Methods
get_column_name(attr)
click to toggle source
# File lib/awesome_hstore_translate/active_record/instance_methods.rb, line 43 def get_column_name(attr) column_name = attr.to_s # detect column from original hstore_translate column_name << '_translations' if !has_attribute?(column_name) && has_attribute?("#{column_name}_translations") column_name end