Module: Mobility::ActiveRecord::AttributeMethods
- Defined in:
- lib/mobility/active_record/attribute_methods.rb
Overview
Included into model if model has ActiveRecord::AttributeMethods among its
ancestors.
Class Method Summary collapse
-
.included(model) ⇒ Array<String>
Adds translated attributes to
attributes.
Instance Method Summary collapse
-
#attributes ⇒ Array<String>
Adds translated attributes to
attributes. -
#translated_attributes ⇒ Array<String>
Translated attributes defined on model.
Class Method Details
.included(model) ⇒ Array<String>
Adds translated attributes to attributes.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mobility/active_record/attribute_methods.rb', line 15 def self.included(model) attributes_method = Module.new do def attributes super.merge(translated_attributes) end end model.class_eval do alias_method :untranslated_attributes, :attributes include attributes_method end end |
Instance Method Details
#attributes ⇒ Array<String>
Adds translated attributes to attributes.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mobility/active_record/attribute_methods.rb', line 15 def self.included(model) attributes_method = Module.new do def attributes super.merge(translated_attributes) end end model.class_eval do alias_method :untranslated_attributes, :attributes include attributes_method end end |
#translated_attributes ⇒ Array<String>
Translated attributes defined on model.
29 30 31 32 33 |
# File 'lib/mobility/active_record/attribute_methods.rb', line 29 def translated_attributes translated_attribute_names.inject({}) do |attributes, name| attributes.merge(name.to_s => send(name)) end end |