OSDN Git Service

Item Dynamic ClassMethods
[pettanr/pettanr.git] / lib / peta / content.rb
index 8458c51..337daa4 100644 (file)
@@ -1,33 +1,55 @@
 module Peta
   class Content < Item
     self.abstract_class = true
-    # ClassMethods
     
-    def self.owner_model
-      nil
+    # Dynamic ClassMethods
+    
+    def self._content?
+      self.my_manifest.content_model
     end
     
-    def self.owner_type
-      :author
+    def self._owner_type
+      self.my_manifest.owner_type
     end
     
-    def self.content?
-      true
+    def self._owner_model
+      t = self.my_manifest.tree['owner']
+      return nil unless t
+      t.parent_model 
     end
     
-    def self.operator operators
-      case self.owner_type
-      when :author
-        operators.author
-      when :artist
-        operators.artist
-      else
-        nil
+    def self._owner_column
+      self.owner_type.to_s + '_id'
+    end
+    
+    def self.load_manifest
+      super
+      f = self._content?
+      define_singleton_method("content?") do 
+        f
+      end
+      t = self._owner_type
+      define_singleton_method("owner_type") do 
+        t
+      end
+      m = self._owner_model
+      define_singleton_method("owner_model") do 
+        m
+      end
+      define_singleton_method("parent_model") do |tree_name|
+        self.my_manifest.tree[tree_name].parent_model
+      end
+      o = self._owner_column
+      define_singleton_method("owner_column") do 
+        o
       end
     end
     
-    def self.owner_column
-      self.owner_type.to_s + '_id'
+    # ClassMethods
+    
+    def self.operator operators
+      return nil unless self.owner_type
+      operators.__send__ self.owner_type
     end
     
     def self.public_list_where
@@ -39,7 +61,6 @@ module Peta
       raise ActiveRecord::Forbidden unless content.own?(operators)
       content
     end
-    
     #InstanceMethods
     
     def owner_model