OSDN Git Service

temp
[pettanr/pettanr.git] / lib / manifest / controller.rb
1
2 module Pettanr
3   class ControllerManager
4     class ActionList
5       def initialize action_name, item_name, operators, list, conf, manifest
6         @action_name = action_name
7         @item_name = item_name
8         @operators = operators
9         @list = list
10         @conf = conf
11         @manifest = manifest
12       end
13       
14       def items 
15         @items ||= @list.items
16       end
17       
18       def filer
19         @filer ||= @manifest.filer_managers[@item_name].open(@item_name, @items, @operators, @list.paginate)
20       end
21       
22     end
23     
24     class ActionShow
25       def initialize action_name, item_name, conf, manifest
26         @action_name = action_name
27         @item_name = item_name
28         @conf = conf
29         @manifest = manifest
30         
31       end
32       
33     end
34     
35     attr :controller_manifest, :item_name, :manifest, :controller_conf, 
36       :actions
37     @@types = {'list' => ActionList, 'show' => ActionShow}
38     def initialize controller_manifest
39       @controller_manifest = controller_manifest
40       @item_name = @controller_manifest.item_name
41       @manifest = @controller_manifest.manifest
42       @controller_conf = @controller_manifest.conf
43       @actions = {}
44       @controller_manifest.actions.each {|action_name, conf|
45         type = conf['type']
46         @actions[action_name] = @@types[type]
47       }
48     end
49     
50     def open action_name, params, operators
51       name = if @controller_conf['item_name']
52         @controller_conf['item_name']
53       else
54         @item_name
55       end
56       list_name = @controller_manifest.list_name action_name
57       @list = @manifest.list_managers[name].open(list_name, params[:page], params[:page_size], operators)
58       @actions[action_name].new action_name, name, operators, @list, @controller_conf, @manifest
59     end
60     
61   end
62 end
63