OSDN Git Service

35cde9c540ec5bde7251357eb82c21331c47485e
[pettanr/pettanr.git] / lib / manifest / local / view / profiler / association.rb
1 require_dependency "manifest/local/view/profiler/association/belongs_to"
2 require_dependency "manifest/local/view/profiler/association/has_many"
3 require_dependency "manifest/local/view/profiler/association/has_one"
4 module Manifest
5   module View
6     module ProfilerModule
7       class Association
8         include AssociationModule
9         attr :profiler, :association_manifest,
10           :belongs_to, :has_many, :has_one
11         def initialize profiler, association_manifest
12           @profiler = profiler
13           @association_manifest = association_manifest
14           @belongs_to = @association_manifest.belongs_to.map {|belongs_to_manifest|
15             BelongsTo.new self, belongs_to_manifest
16           }
17           @has_many = @association_manifest.has_many.map {|list_name|
18             HasMany.new self, list_name
19           }
20           @has_one = @association_manifest.has_one.map {|list_name|
21             HasOne.new self, list_name
22           }
23         end
24         
25         def item
26           @profiler.item
27         end
28         
29         def model_manifest
30           ::Manifest.manifest.models[@profiler.item_name]
31         end
32         
33         def model_attribute_manifest
34           model_manifest.attributes[@column_name]
35         end
36         
37         def template_dir 
38           @profiler.template_dir
39         end
40         
41         def template_file_name
42           "associations"
43         end
44         
45         def template_name
46           self.template_dir + self.template_file_name
47         end
48         
49         def each_belongs_to_filer
50           @belongs_to.each {|b|
51             yield b.filer
52           }
53         end
54         
55         def each_has_many_filer
56           @has_many.each {|h|
57             yield h.filer
58           }
59         end
60         
61         def each_has_one_filer
62           @has_one.each {|h|
63             yield h.filer
64           }
65         end
66         
67       end
68     end
69   end
70 end