39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/wakari/models/translation/model.rb', line 39
def acts_as_translation_class(content_class, association_name, meta_class, full_association_name, options)
has_locale! *Array.wrap(options[:locales])
belongs_to :content, :class_name => "::Object::#{content_class.name}", :inverse_of => association_name, :counter_cache => :"#{association_name}_count"
belongs_to :meta, :class_name => "::Object::#{meta_class.name}", :inverse_of => full_association_name, :counter_cache => :wakari_used
self._meta_attributes =
if meta_class < Wakari::Meta::Text || meta_class < Wakari::Meta::String
[:value]
else
Array.wrap(options[:attributes]).map {|a| a.to_sym}
end
attr_accessible *_meta_attributes, :content_id, :meta_id, :_destroy, :position
delegate *_meta_attributes, :to_s, :to => "(@_template_meta||meta)"
delegate *_meta_attributes.collect {|attribute| "#{attribute}="}, :to => :template_meta
(class << self; self; end).instance_eval do
define_method :i18n_inherited_namespaced_scope do |resource| :"#{content_class.i18n_namespaced_scope(resource)}.#{model_name.element}"
end
define_method :i18n_inherited_default_scope do |resource| :"#{content_class.i18n_default_scope(resource)}.#{model_name.element}"
end
end
define_method :stack do
content.send(association_name)
end
end
|