Module: Globalize::ActiveRecord::InstanceMethods

Defined in:
lib/globalize/active_record/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#attribute_namesObject



22
23
24
# File 'lib/globalize/active_record/instance_methods.rb', line 22

def attribute_names
  translated_attribute_names.map(&:to_s) + super
end

#attributesObject



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

#globalizeObject



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(options = nil)
  translated_attribute_names.each { |name| @attributes.delete(name.to_s) }
  globalize.reset
  super(options)
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(options)
  options.keys.each do |locale|
    translation = translations.find_by_locale(locale.to_s) ||
      translations.build(:locale => locale.to_s)
    translation.update_attributes!(options[locale])
  end
end

#translated_attributesObject



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