3 cattr_accessor :manifest
4 attr :system_resources, :magic_numbers, :select_items,
5 :controllers, :models, :lists, :profilers, :filers, :forms, :lists
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']
16 # managers can't initialize at application.rb
17 # call me after configured Rails Application
19 return unless defined? ::Pettanr
20 @controllers = Controller.manager(self, @manifest['controllers'])
21 @models = Model.manager(self, @manifest['models'])
22 @locals = @manifest['locals']
23 @filers = Filer.manager(self, @locals['filers'])
24 @profilers = Profiler.manager(self, @locals['profilers'])
25 @forms = Form.base_manager(self, @locals['forms'])
26 @forms.merge(Form.extend_manager(self, @locals['forms']))
27 @lists = List.manager(self, @locals['lists'])
33 def select_items_loader
34 @system_resources.select_items['model_loader'].each {|name, conf|
35 model_name = conf['model_name']
36 list_name = conf['list_name'] || 'select_items'
37 caption = conf['caption']
38 list = @lists[model_name][list_name]
39 @select_items['model'] ||= {}
40 @select_items['model'][name] = list.items.map {|item| [item.caption, item.id]}
46 @controllers.each do |controller_name, controller|
47 model_name = controller.model_name
48 next if model_name.blank?
49 controller.actions.each do |action_name, conf|
50 next unless conf['type'] == 'list'
51 list_name = conf['list']['list_name']
52 list = Pettanr::Application::manifest.list_managers[model_name]
53 list.add_action action_name, list_name
66 Manifest.manifest = Manifest.new json
69 def item_name_to_model item_name
70 item_name.classify.constantize