OSDN Git Service

239999851ed649cba2897c6625957b653790c2f6
[pettanr/pettanr.git] / lib / peta / element_nestable_content.rb
1 module Peta
2   class ElementNestableContent < Content
3     self.abstract_class = true
4     
5     # Dynamic Methods
6     
7     def self.load_manifest
8       super
9       return nil if self._skip_load?
10       # Class Methods
11       # Instance Methods
12       define_method("element_items") do |element_model|
13         self.__send__ self.class.my_manifest.associations.child_element_name(element_model)
14       end
15       define_method("elements_items") do 
16         self.class.child_models.map {|element_model|
17           self.element_items element_model
18         }.flatten
19       end
20     end
21     
22     # Class Methods
23     
24     # Instance Methods
25     
26     def boosts level
27       super
28       self.elements_items.each do |item|
29         item.boosts level
30       end
31     end
32     
33     def post_attributes opt = {}
34       attr = self.copy_attributes
35       hash = {}
36       self.class.child_models.each do |element_model|
37         name = self.class.my_manifest.associations.child_element_name(element_model) + '_attributes'
38         hash[name] ||= {}
39         e=   self.class.child_models.map {|element_model|
40           self.element_items element_model
41         }.flatten
42
43         e.each do |element|
44           hash[name][element.post_attribute_key] = element.post_attributes opt
45         end
46       end
47       attr.merge hash
48     end
49     
50   end
51 end
52