OSDN Git Service

fix picture io:
[pettanr/pettanr.git] / lib / peta / content.rb
index 8458c51..65a10fa 100644 (file)
@@ -1,54 +1,59 @@
 module Peta
   class Content < Item
     self.abstract_class = true
-    # ClassMethods
     
-    def self.owner_model
-      nil
-    end
+    # Dynamic Methods
     
-    def self.owner_type
-      :author
+    def self.load_manifest
+      super
+      return nil if self._skip_load?
+      # Class Methods
+      ct = self.my_manifest.content_model?
+      define_singleton_method("content?") do 
+        ct
+      end
+      ot = self.my_manifest.owner_type
+      define_singleton_method("owner_type") do 
+        ot
+      end
+      om = self.parent_model
+      define_singleton_method("owner_model") do 
+        om
+      end
+      oc = self.owner_type.to_s + '_id'
+      define_singleton_method("owner_column") do 
+        oc
+      end
+      # Instance Methods
     end
     
-    def self.content?
-      true
-    end
+    # Class Methods
     
     def self.operator operators
-      case self.owner_type
-      when :author
-        operators.author
-      when :artist
-        operators.artist
-      else
-        nil
-      end
+      return nil unless self.owner_type
+      operators.__send__ self.owner_type
     end
     
-    def self.owner_column
-      self.owner_type.to_s + '_id'
-    end
-    
-    def self.public_list_where
-      ''
+    def self.public_list_where list
+      nil
     end
     
     def self.edit content_id, operators
-      content = self.find content_id, self.show_opt
+      content = self.find content_id
       raise ActiveRecord::Forbidden unless content.own?(operators)
       content
     end
     
-    #InstanceMethods
+    # Instance Methods
     
     def owner_model
       self.class.owner_model ? self.__send__(self.class.owner_model.item_name) : self
     end
     
+    # super return if my item
     def visible? operators
       super
-      return true if owner_model.own?(operators)
+      return nil if owner_model.own?(operators)
       true
     end