OSDN Git Service

fix remove tree
[pettanr/pettanr.git] / lib / manifest / manifest.rb
index 94e47a8..070d712 100644 (file)
@@ -1,55 +1,33 @@
 module Manifest
   class Manifest
     cattr_accessor :manifest
-    attr :system_resources, :magic_numbers, :select_items,
-      :controllers, :models, :lists, :profilers, :filers, :forms
+    attr :system_resources, :magic_numbers,
+      :items, :controllers, :models, :module_names
     # call me before load routes.rb
     # routes.rb needs engine_resources manifest in system_resources
     # ex. it's adding license_groups routes
-    def initialize manifest
-      @manifest = manifest || {}
-      @system_resources = SystemResources.new(self, SystemResources.set_default(@manifest['system_resources']))
-      @magic_numbers = @manifest['magic_numbers']
-      @select_items = @manifest['select_items']
+    def initialize global_json
+      @module_names = []
+      @global_json = global_json || {}
+      @system_resources = SystemResource.new(self, SystemResource.set_default(@global_json['system_resources']))
+      @magic_numbers = @global_json['magic_numbers']
     end
     
-    # managers can't initialize at application.rb
-    # call me after configured Rails Application
     def init
-      @controllers = Controller.manager(self, @manifest['controllers'])
-      @models = Model.manager(self, @manifest['models'])
-      @locals = @manifest['locals']
-      @filers = Filer.manager(self, @locals['filers'])
-      @profilers = Profiler.manager(self, @locals['profilers'])
-      @forms = Form.base_manager(self, @locals['forms'])
-      @forms.merge(Form.extend_manager(self, @locals['forms']))
-      select_items_loader
-      add_action
+      # managers can't initialize before load  application.rb
+      return unless defined? ::Pettanr
+      @items = ManifestBase.load_type_name_args(self, @global_json, 'items', ItemFactory)
+      @controllers = Controller.load(self, @global_json, 'controllers')
+      @models = Model.load(self, @global_json, 'models')
     end
     
-    # call after load app
-    def select_items_loader
-      @system_resources.select_items['model_loader'].each {|name, conf|
-        model_name = conf['model_name']
-        list_name = conf['list_name'] || 'select_items'
-        caption = conf['caption']
-        list = @lists[model_name][list_name]
-        @select_items['model'] ||= {}
-        @select_items['model'][name] = list.items.map {|item| [item.caption, item.id]}
-      }
+    def system_resources_init
+      @system_resources.init
     end
     
-    def add_action
-        return
-      @controllers.each do |controller_name, controller|
-        model_name = controller.model_name
-        next if model_name.blank?
-        controller.actions.each do |action_name, conf|
-          next unless conf['type'] == 'list'
-          list_name = conf['list']['list_name']
-          list = Pettanr::Application::manifest.list_managers[model_name]
-          list.add_action action_name, list_name
-        end
+    def load_models_manifest
+      @models.each do |model_name, model|
+        model.classify.load_manifest
       end
     end
     
@@ -60,14 +38,22 @@ module Manifest
       Manifest.manifest
     end
     
-    def load json
-      Manifest.manifest = Manifest.new json
+    def load global_json
+      Manifest.manifest = Manifest.new global_json
     end
     
     def item_name_to_model item_name
       item_name.classify.constantize
     end
     
+    def singularize name
+      name.singularize
+    end
+    
+    def pluralize name
+      name.pluralize
+    end
+    
   end
 
   extend ModuleMethods