-
-module Pettanr
+module Manifest
class Manifest
- class Controller
- attr :conf, :attributes, :associations
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
- @model_name = @conf['model_name']
- end
-
- def actions
- @model_manifest['actions'] || {}
- end
-
- end
-
- class Model
- attr :item_name, :conf, :manifest, :attributes, :associations
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
- end
-
- def attributes
- @model_manifest['attributes'] || {}
- end
-
- def associations
- @conf['name'] || {}
- end
-
- end
-
- class List
- attr :item_name, :conf, :manifest, :default_page_size
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
- @default_page_size = @conf['default_page_size'] || 20
- end
-
- end
-
- class License
- attr :conf
- def initialize manifest
- @manifest = manifest
- @conf = @manifest['licenses'] || {}
- end
- end
-
- class Element
- attr :conf
- def initialize manifest
- @manifest = manifest
- @conf = @manifest['elements'] || {}
- end
- end
-
- class SpeechBalloonTemplate
- attr :conf
- def initialize manifest
- @manifest = manifest
- @conf = @manifest['speech_balloon_templates'] || {}
- end
- end
-
- class WritingFormat
- attr :conf
- def initialize manifest
- @manifest = manifest
- @conf = @manifest['writing_formats'] || {}
- end
+ cattr_accessor :manifest
+ attr :system_resources, :magic_numbers,
+ :controllers, :models
+ # call me before load routes.rb
+ # routes.rb needs engine_resources manifest in system_resources
+ # ex. it's adding license_groups routes
+ def initialize global_json
+ @global_json = global_json || {}
+ @system_resources = SystemResource.new(self, SystemResource.set_default(@global_json['system_resources']))
+ @magic_numbers = @global_json['magic_numbers']
end
- class Profile
- attr :conf
- def initialize manifest
- @manifest = manifest
- @conf = @manifest['profile'] || {}
- end
- end
-
- class Profiler
- attr :item_name, :conf, :manifest, :columns, :belongs_to, :has_many, :has_one
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
- @columns = @conf['columns'] || {}
- @associations_conf = @conf['associations'] || {}
- @belongs_to = @associations_conf['belongs_to'] || []
- @has_many = @associations_conf['has_many'] || []
- @has_one = @associations_conf['has_one'] || []
- end
-
+ def init
+ # managers can't initialize before load application.rb
+ return unless defined? ::Pettanr
+ @controllers = Controller.manager(self, @global_json['controllers'] || {})
+ @models = Model.manager(self, @global_json['models'] || {})
end
- class Filer
- attr :item_name, :conf, :manifest, :icon, :symbol, :caption, :summary, :date, :edit
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
- @symbol = @conf['symbol']
- @caption = @conf['caption']
- @summary = @conf['summary']
- @icon = @conf['icon']
- @date = @conf['date']
- @edit = @conf['edit']
- end
-
+ def system_resources_init
+ @system_resources.init
end
- class Form
- attr :item_name, :conf, :manifest, :icon, :symbol, :caption, :summary, :date, :edit
- def initialize item_name, conf, manifest
- @item_name = item_name
- @conf = conf || {}
- @manifest = manifest
+ def load_models_manifest
+ @models.each do |model_name, model|
+ model.classify.load_manifest
end
-
- end
-
- attr :licenses, :elements, :speech_balloon_templates, :writing_formats, :profile,
- :model_managers, :list_managers, :profiler_managers, :filer_managers, :form_managers
- def initialize manifest
- @manifest = manifest || {}
- @controllers = {}
- @models = {}
- @lists = {}
- @licenses = License.new(manifest)
- @elements = Element.new(manifest)
- @speech_balloon_templates = SpeechBalloonTemplate.new(manifest)
- @writing_formats = WritingFormat.new(manifest)
- @profile = Profile.new(manifest)
- @profilers = {}
- @filers = {}
- @forms = {}
- @model_managers = {}
- @list_managers = {}
- @profiler_managers = {}
- @filer_managers = {}
- @form_managers = {}
- (@manifest['controllers'] || {}).each {|item_name, controller_conf|
- @controllers[item_name] = Controller.new(item_name, controller_conf, manifest)
- }
- (@manifest['models'] || {}).each {|item_name, model_conf|
- @models[item_name] = Model.new(item_name, model_conf, manifest)
- @model_managers[item_name] = Pettanr::ModelManager.new @models[item_name]
- }
- (@manifest['lists'] || {}).each {|item_name, list_conf|
- @lists[item_name] = List.new(item_name, list_conf, manifest)
- @list_managers[item_name] = Pettanr::ListManager.new @lists[item_name]
- }
- @locals = @manifest['locals'] || {}
- (@locals['profilers'] || {}).each {|item_name, profiler_conf|
- @profilers[item_name] = Profiler.new item_name, profiler_conf, manifest
- @profiler_managers[item_name] = Pettanr::ProfilerManager.new @profilers[item_name]
- }
- (@locals['filers'] || {}).each {|item_name, filer_conf|
- @filers[item_name] = Filer.new item_name, filer_conf, manifest
- @filer_managers[item_name] = Pettanr::FilerManager.new @filers[item_name]
- }
- (@locals['forms'] || {}).each {|item_name, form_conf|
- @forms[item_name] = Form.new item_name, form_conf, manifest
- @form_managers[item_name] = Pettanr::FormManager.new @forms[item_name]
- }
- end
-
- def controller item_name
- @controllers[item_name] || @mcontrollers[item_name.tableize]
end
- def model item_name
- @models[item_name] || @models[item_name.tableize]
+ end
+
+ module ModuleMethods
+ def manifest
+ Manifest.manifest
end
- def list item_name
- @lists[item_name] || @lists[item_name.tableize]
+ def load global_json
+ Manifest.manifest = Manifest.new global_json
end
- def profiler item_name
- @profilers[item_name] || @profilers[item_name.tableize]
+ def item_name_to_model item_name
+ item_name.classify.constantize
end
- def filer item_name
- @filers[item_name] || @filers[item_name.tableize]
+ def singularize name
+ name.singularize
end
- def form item_name
- @forms[item_name] || @forms[item_name.tableize]
+ def pluralize name
+ name.pluralize
end
end
-
+
+ extend ModuleMethods
end