5
6
7
8
9
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
|
# File 'lib/translatable/active_record/macro.rb', line 5
def translatable(*attr_names)
options = attr_names.
setup_translatable!(options) unless translatable?
attr_names = attr_names.map(&:to_sym)
attr_names -= translated_attribute_names if defined?(translated_attribute_names)
if attr_names.present?
attr_names.each do |attr_name|
translated_attr_accessor(attr_name)
translations_accessor(attr_name)
self.translated_attribute_names << attr_name
if options[:only]
self.translated_serialized_attributes[attr_name] = options[:only] ? options[:only] : []
end
end
on_after_save_callback(attr_names, options[:after_save]) if options[:after_save]
on_before_save_callback(attr_names, options[:before_save]) if options[:before_save]
on_after_update_callback(attr_names, options[:after_update]) if options[:after_update]
on_before_update_callback(attr_names, options[:before_update]) if options[:before_update]
Translatable.add_translatable self
end
end
|