OSDN Git Service

087f791951375ef5242136aefdc4e453d50013e8
[pettanr/pettanr.git] / lib / manifest / model.rb
1 require_dependency "manifest/model/attribute"
2 require_dependency "manifest/model/association"
3 require_dependency "manifest/model/list"
4
5 module Manifest
6   class Model
7     
8     def self.manager manifest, my_manifests
9       models = {}
10       my_manifests.each {|model_name, model_manifest|
11         models[model_name] = self.new(manifest, model_name, model_manifest)
12       }
13       models
14     end
15     
16     attr :model_name, :model_manifest, 
17       :attributes, :associations, :lists
18     def initialize manifest, model_name, model_manifest
19       @manifest = manifest
20       @model_name = model_name
21       @model_manifest = model_manifest
22       self.set_default
23       self.init
24     end
25     
26     def set_default
27       @model_manifest['attributes'] ||= {}
28       @model_manifest['associations'] ||= {}
29       @model_manifest['lists'] ||= {}
30     end
31     
32     def init
33       @attributes = {}
34       @model_manifest['attributes'].each {|attribute_name, attribute_manifest|
35         @attributes[attribute_name] = ModelModule::Attribute.new(self, attribute_name, attribute_manifest)
36       }
37       @associations = {}
38       @model_manifest['associations'].each {|association_name, association_manifest|
39         @associations[association_name] = ModelModule::Association.new(self, association_name, association_manifest)
40       }
41       @lists = {}
42       @model_manifest['lists'].each {|list_name, list_manifest|
43         @lists[list_name] = ModelModule::ListFactory.factory(self, list_name, list_manifest)
44       }
45     end
46     
47   end
48 end
49