3 cattr_accessor :manifest
4 attr :system_resources, :magic_numbers, :select_items,
5 :controllers, :models, :lists, :profilers, :filers, :forms, :lists, :views
6 # call me before load routes.rb
7 # routes.rb needs engine_resources manifest in system_resources
8 # ex. it's adding license_groups routes
9 def initialize manifest
10 @manifest = manifest || {}
11 @system_resources = SystemResources.new(self, SystemResources.set_default(@manifest['system_resources']))
12 @magic_numbers = @manifest['magic_numbers']
13 @select_items = @manifest['select_items']
17 # managers can't initialize before load application.rb
18 return unless defined? ::Pettanr
19 @controllers = Controller.manager(self, @manifest['controllers'])
20 @models = Model.manager(self, @manifest['models'])
21 @locals = @manifest['locals']
22 @filers = Filer.manager(self, @locals['filers'])
23 @profilers = Profiler.manager(self, @locals['profilers'])
24 @forms = Form.base_manager(self, @locals['forms'])
25 @forms.merge(Form.extend_manager(self, @locals['forms']))
26 @lists = List.manager(self, @locals['lists'])
27 @views = View.new self
33 def select_items_loader
34 @system_resources.select_items['model_loader'].each {|name, conf|
35 raise "undefined model_name for select_items > model_loader > #{name}\n" unless conf['model_name']
36 model_name = conf['model_name']
37 list_name = conf['list_name'] || 'select_items'
38 caption = conf['caption_name'] || 'caption'
39 list_group = @lists[model_name]
40 raise "undefined list for select_items > model_loader > #{name} > model_name > #{model_name} \n" unless list_group
41 list = list_group[list_name]
42 raise "undefined list for select_items > model_loader > #{name} > list_name > #{list_name} \n" unless list
43 @select_items['model'] ||= {}
44 r = list.open operators, options
45 @select_items['model'][name] = r.items.map {|item| [item.attributes[caption], item.id]}
51 @controllers.each do |controller_name, controller|
52 model_name = controller.model_name
53 next if model_name.blank?
54 controller.actions.each do |action_name, conf|
55 next unless conf['type'] == 'list'
56 list_name = conf['list']['list_name']
57 list = Pettanr::Application::manifest.list_managers[model_name]
58 list.add_action action_name, list_name
71 Manifest.manifest = Manifest.new json
74 def item_name_to_model item_name
75 item_name.classify.constantize