OSDN Git Service

3dc1cf07c8fbb37bd0d677e4087b695f7dec3aba
[pettanr/pettanr.git] / lib / manifest / profiler / association.rb
1 require_dependency "manifest/profiler/association/belongs_to"
2 require_dependency "manifest/profiler/association/has_many"
3 require_dependency "manifest/profiler/association/has_one"
4 module Manifest
5   module ProfilerModule
6     class Association
7       include AssociationModule
8       attr :profiler, :association_manifest, 
9         :belongs_to, :has_many, :has_one
10       def initialize profiler, association_manifest
11         @profiler = profiler
12         @association_manifest = association_manifest
13         self.set_default
14         self.init
15       end
16       
17       def set_default
18         @association_manifest['belongs_to'] ||= []
19         @association_manifest['has_many'] ||= []
20         @association_manifest['has_one'] ||= []
21       end
22       
23       def init
24         @belongs_to = []
25         @has_many = []
26         @has_one = []
27         @association_manifest['belongs_to'].each {|model_name|
28           @belongs_to << BelongsTo.new(self, model_name)
29         }
30         @association_manifest['has_many'].each {|list_name|
31           @has_many << HasMany.new(self, list_name)
32         }
33         @association_manifest['has_one'].each {|list_name|
34           @has_one << HasOne.new(self, list_name)
35         }
36       end
37       
38       def profiler_name
39         @profiler.model_name
40       end
41       
42       def profiler_manifest
43         @profiler.profiler_manifest
44       end
45       
46     end
47     
48   end
49 end