OSDN Git Service

d414bb10728298f2e3924a39ee30fcfd2f9a78b2
[pettanr/pettanr.git] / lib / manifest / model.rb
1
2 module Pettanr
3   module Manifest
4     class Model
5       def self.set_default my_manifest
6         my_manifest.each {|item_name, model_manifest|
7           model_manifest['attributes'] ||= {}
8           model_manifest['associations'] ||= {}
9           model_manifest|['attributes'].each {|attribute_name, attribute_manifest|
10             attribute_manifest.each {|attribute_name, attribute_manifest|
11               raise "undefined type for models > #{item_name} > attributes > #{attribute_name}\n" unless attribute_manifest['type']
12               attribute_manifest['primary_key'] ||= 0
13               attribute_manifest['rules'] ||= {}
14               attribute_manifest['rules'].each {|rule_name, rule_manifest|
15                 # 'required' 'number'
16               }
17             }
18           }
19           model_manifest|['associations'].each {|association_name, association_manifest|
20             association_manifest['belongs_to'] ||= {}
21             association_manifest['has_many'] ||= {}
22             association_manifest['has_one'] ||= {}
23             association_manifest['belongs_to'].each {|belongs_to_name, belongs_to_manifest|
24               belongs_to_manifest['id_column'] ||= belongs_to_name + '_id' 
25             }
26             association_manifest['has_many'].each {|has_many_name, has_many_manifest|
27               raise "undefined foreign_key for models > #{item_name} > associations > has_many > #{has_many_name}\n" unless has_many_manifest['foreign_key']
28               has_many_manifest['model'] ||= has_many_name.singularize
29               # 'through'
30             }
31             association_manifest['belongs_to'].each {|belongs_to_name, belongs_to_manifest|
32               belongs_to_manifest['id_column'] ||= belongs_to_name + '_id' 
33             }
34           }
35         }
36       end
37       
38       def initialize model_manifest
39         @model_manifest = model_manifest
40         @item_name = @model_manifest.item_name
41         @manifest = @model_manifest.manifest
42         @model_conf = @model_manifest.conf
43       end
44       
45       def open list_name, page, page_size, operators
46       end
47       
48     end
49   end
50 end
51