class Manifest
cattr_accessor :manifest
attr :system_resources, :magic_numbers,
- :controllers, :models, :lists, :profilers, :filers, :forms, :lists, :views
+ :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 = SystemResource.new(self, SystemResource.set_default(@manifest['system_resources']))
- @magic_numbers = @manifest['magic_numbers']
+ 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
def init
# managers can't initialize before load application.rb
return unless defined? ::Pettanr
- @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']))
- @lists = List.manager(self, @locals['lists'])
+ @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')
+ #
+ @items.each do |name, peta_manifest|
+ peta_manifest.init_after_load_manifest
+ end
+ end
+
+ def init_after_load_manifest
@system_resources.init
- add_action
- 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
+ end
+
+ def load_models_manifest
+ @models.each do |model_name, model|
+ model.classify.load_manifest
end
end
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