Module: Puret::ActiveRecordExtensions::InstanceMethods

Defined in:
lib/puret/active_record_extensions.rb

Instance Method Summary collapse

Instance Method Details

#puret_attributesObject

attributes are stored in @puret_attributes instance variable via setter



72
73
74
# File 'lib/puret/active_record_extensions.rb', line 72

def puret_attributes
  @puret_attributes ||= Hash.new { |hash, key| hash[key] = {} }
end

#puret_default_localeObject



65
66
67
68
69
# File 'lib/puret/active_record_extensions.rb', line 65

def puret_default_locale
  return default_locale.to_sym if respond_to?(:default_locale)
  return self.class.default_locale.to_sym if self.class.respond_to?(:default_locale)
  I18n.default_locale
end

#update_translations!Object

called after save



77
78
79
80
81
82
83
84
# File 'lib/puret/active_record_extensions.rb', line 77

def update_translations!
  return if puret_attributes.blank?
  puret_attributes.each do |locale, attributes|
    translation = translations.find_or_initialize_by_locale(locale.to_s)
    translation.attributes = translation.attributes.merge(attributes)
    translation.save!
  end
end