10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/globalize/active_record/act_macro.rb', line 10
def translates(*attr_columns)
return if translates?
options = attr_columns.
options[:table_name] ||= "#{table_name.singularize}_translations"
attrs_hash = Utils.convert_columns(attr_columns)
attr_names = attrs_hash.keys
class_attribute :translated_attribute_names, :translation_options,
:fallbacks_for_empty_translations, :translated_columns_hash
self.translated_attribute_names = attr_names.map(&:to_sym)
self.translation_options = options
self.translated_columns_hash = attrs_hash
self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
include InstanceMethods, Accessors
extend ClassMethods, Migration
has_many :translations, :class_name => translation_class.name,
:foreign_key => class_name.foreign_key,
:dependent => :destroy,
:extend => HasManyExtensions
before_save :update_checkers!
after_create :save_translations!
after_update :save_translations!
if options[:versioning]
::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
translation_class.has_paper_trail
delegate :version, :versions, :to => :translation
end
attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
end
|