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
|
# File 'lib/wakari/models/proxy/model.rb', line 12
def acts_as_proxy(translation_class, association_name, options)
lang_methods = translation_class._locales.collect do |lang|
method = lang.to_method
class_eval <<-EOV
def #{method}
translation?(\"#{lang.code}\")
end
def #{method}=(params={})
detect_translation(\"#{lang.code}\").tap do |t|
t.attributes = params.delete_if {|k| k.to_s == \"locale\"}
end
end
EOV
method
end
attr_accessible *lang_methods
delegate *translation_class._meta_attributes, :to => :current_translation, :allow_nil => true
delegate *translation_class._meta_attributes.collect {|attribute| "#{attribute}="}, :to => :detect_current_translation, :allow_nil => true
if self < Wakari::Proxy::Base
define_method :translations do |*args|
content.send(association_name, *args)
end
end
end
|