OSDN Git Service

merge
[pettanr/pettanr.git] / lib / local_manifest / profiler.rb
1 require_dependency "local_manifest/profiler/column"
2 require_dependency "local_manifest/profiler/list"
3 require_dependency "local_manifest/profiler/association"
4 module LocalManifest
5   class Profiler
6     
7     def self.manager manifest, my_manifests
8       profilers = {}
9       my_manifests.each {|item_name, profiler_manifest|
10         profilers[item_name] = self.new(manifest, item_name, profiler_manifest)
11       }
12       profilers
13     end
14     
15     attr :profiler_manifest, :item_name, :manifest, 
16       :column_names, :lists, :associations
17     def initialize manifest, item_name, profiler_manifest
18       @manifest = manifest
19       @item_name = item_name
20       @profiler_manifest = profiler_manifest
21       self.set_default
22       self.init
23     end
24     
25     def set_default
26       @profiler_manifest['column_names'] ||= []
27       @profiler_manifest['lists'] ||= {}
28       @profiler_manifest['associations'] ||= {}
29     end
30     
31     def init
32       @column_names = ['id'] + @profiler_manifest['column_names'] + ['created_at', 'updated_at']
33       @lists = {}
34       @profiler_manifest['lists'].each {|list_name, list_manifest|
35         @lists[list_name] = ProfilerModule::List.new(self, list_name, list_manifest)
36       }
37       @associations = ProfilerModule::Association.new(self, @profiler_manifest['associations'])
38     end
39     
40     def each_column
41       @column_names
42     end
43     
44   end
45   
46 end
47