Module: HasManyTranslations::Creation::ClassMethods
- Defined in:
- lib/has_many_translations/creation.rb
Overview
Class methods added to ActiveRecord::Base to facilitate the creation of new translations.
Instance Method Summary collapse
-
#prepare_translated_options_with_creation(options) ⇒ Object
Overrides the basal
prepare_has_translations_options
method defined in HasManyTranslations::Options to extract the:only
and:except
options intohas_many_translations_options
.
Instance Method Details
#prepare_translated_options_with_creation(options) ⇒ Object
Overrides the basal prepare_has_translations_options
method defined in HasManyTranslations::Options to extract the :only
and :except
options into has_many_translations_options
.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/has_many_translations/creation.rb', line 26 def () self.columns.map{|c|c.type == :string || c.type == :text ? c.name : nil}.compact.each{|name| #alias_method "#{name}_before_translation", name.to_sym #unless try(name) define_method name, lambda { |*args| # if self.translations.blank? || self.translations.first.origin_locale_code == self.hmt_locale || read_attribute(name.to_sym).nil? read_attribute(name.to_sym) else trans = self.translations.first(:conditions => {:locale_code => self.hmt_locale, :model_attribute => name}) val = trans.nil? ? read_attribute(name.to_sym) : trans.value #self.hmt_locale end #HasManyTranslations.fetch(args.first || self.class.locale || I18n.locale, name) } alias_method "#{name}_before_type_cast", name } result = () self.[:only] = Array(.delete(:only)).map(&:to_s).uniq if [:only] self.[:except] = Array(.delete(:except)).map(&:to_s).uniq if [:except] self.[:locales] = Array(.delete(:locales)).map(&:to_s).uniq if [:locales] self.[:default_languages] = [:default_languages] ? Array(.delete(:default_languages)).map(&:to_s).uniq : nil self.[:languages] = [:languages] ? Array(.delete(:languages)).map(&:to_s).uniq : nil # self.has_many_translations_options[:force_on_update] = options[:force_on_update] ? Array(options.delete(:force_on_update)).map(&:to_s).uniq : nil result end |