Module: Globalize::ActiveRecord::InstanceMethods
- Defined in:
- lib/globalize/active_record/instance_methods.rb
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes, *args) ⇒ Object
- #globalize ⇒ Object
- #reload(options = nil) ⇒ Object
- #set_translations(options) ⇒ Object
- #translated_attributes ⇒ Object
Instance Method Details
#attribute_names ⇒ Object
22 23 24 |
# File 'lib/globalize/active_record/instance_methods.rb', line 22 def attribute_names translated_attribute_names.map(&:to_s) + super end |
#attributes ⇒ Object
10 11 12 |
# File 'lib/globalize/active_record/instance_methods.rb', line 10 def attributes super.merge(translated_attributes) end |
#attributes=(attributes, *args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/globalize/active_record/instance_methods.rb', line 14 def attributes=(attributes, *args) if locale = attributes.try(:delete, :locale) Globalize.with_locale(locale) { super } else super end end |
#globalize ⇒ Object
6 7 8 |
# File 'lib/globalize/active_record/instance_methods.rb', line 6 def globalize @globalize ||= Adapter.new self end |
#reload(options = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/globalize/active_record/instance_methods.rb', line 40 def reload( = nil) translated_attribute_names.each { |name| @attributes.delete(name.to_s) } globalize.reset super() end |
#set_translations(options) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/globalize/active_record/instance_methods.rb', line 32 def set_translations() .keys.each do |locale| translation = translations.find_by_locale(locale.to_s) || translations.build(:locale => locale.to_s) translation.update_attributes!([locale]) end end |
#translated_attributes ⇒ Object
26 27 28 29 30 |
# File 'lib/globalize/active_record/instance_methods.rb', line 26 def translated_attributes translated_attribute_names.inject({}) do |attributes, name| attributes.merge(name.to_s => send(name)) end end |