Module: Purizumu::ModelExtensions::ClassMethods
- Defined in:
- lib/purizumu/model_extensions.rb
Overview
Defines translated attribute readers on Active Record models.
Instance Method Summary collapse
Instance Method Details
#attribute_translation(*attribute_names) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/purizumu/model_extensions.rb', line 13 def attribute_translation(*attribute_names) translated_attribute_names = attribute_names.flatten.map(&:to_s) self.purizumu_translated_attributes = ( purizumu_translated_attributes + translated_attribute_names ).uniq after_commit :purizumu_clear_translations_after_commit, on: :update translated_attribute_names.each do |attribute_name| define_method(attribute_name) do Purizumu.translate_attribute(self, attribute_name) end end end |