OSDN Git Service

separate manifest
[pettanr/pettanr.git] / lib / locmare / profiler / association.rb
1 require_dependency "locmare/profiler/association/belongs_to"
2 require_dependency "locmare/profiler/association/has_many"
3 require_dependency "locmare/profiler/association/has_one"
4 module Locmare
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         @belongs_to = @association_manifest.belongs_to.map {|belongs_to_manifest|
14           BelongsTo.new self, belongs_to_manifest
15         }
16         @has_many = @association_manifest.has_many.map {|list_name|
17           HasMany.new self, list_name
18         }
19         @has_one = @association_manifest.has_one.map {|list_name|
20           HasOne.new self, list_name
21         }
22       end
23       
24       def item
25         @profiler.item
26       end
27       
28       def model_manifest
29         ::Manifest.manifest.models[@profiler.item_name]
30       end
31       
32       def model_attribute_manifest
33         model_manifest.attributes[@column_name]
34       end
35       
36       def template_dir 
37         @profiler.template_dir
38       end
39       
40       def template_file_name
41         "associations"
42       end
43       
44       def template_name
45         self.template_dir + self.template_file_name
46       end
47       
48       def each_belongs_to_filer
49         @belongs_to.each {|b|
50           yield b.filer
51         }
52       end
53       
54       def each_has_many_filer
55         @has_many.each {|h|
56           yield h.filer
57         }
58       end
59       
60       def each_has_one_filer
61         @has_one.each {|h|
62           yield h.filer
63         }
64       end
65       
66     end
67   end
68 end