OSDN Git Service

element
[pettanr/pettanr.git] / lib / manifest / model.rb
index 876b0a4..f11b84a 100644 (file)
@@ -64,6 +64,55 @@ module Manifest
       ::Manifest.item_name_to_model @model_name
     end
     
+    def table_name
+      self.classify.table_name
+    end
+    
+    def valid_encode_columns
+      r = []
+      @attributes.each {|attribute_name, attribute|
+        next unless attribute.type == 'text'
+        r << attribute_name
+      }
+      r
+    end
+    
+    def owner_type
+      return :author if @attributes['author_id']
+      return :artist if @attributes['artist_id']
+      false
+    end
+    
+    def content_model
+      return true if self.owner_type
+      false
+    end
+    
+    def each_child_model_manifest tree_name
+      ::Manifest.models.each {|child_model_name, child_model_manifest|
+        next unless child_model_manifest.tree[tree_name]
+        next unless child_model_manifest.tree[tree_name].parent_model_name == @model_name
+        yield child_model_manifest
+      }
+    end
+    
+    def child_models tree_name
+      r = []
+      self.each_child_model_manifest(tree_name) {|child_model_manifest|
+        r << child_model_manifest.classify
+      }
+      r
+    end
+    
+    def child_element_names tree_name
+      r = []
+      self.each_child_model_manifest(tree_name) {|child_model_manifest|
+        # has_one ?
+        r << self.associations.child_element_name(child_model_manifest.model_name)
+      }
+      r
+    end
+    
   end
 end