orbit4-5/lib/orbit_app/module/registration.rb

55 lines
1.2 KiB
Ruby

#This is a core class of Orbit Kernel. This class will register a module and set the properties defined in the module's initializer
#file.
module OrbitApp
module Module
module Registration
module ClassMethods
@@registrations = []
def new(name,&block)
@@registrations << RegisteredModule.new(name,&block)
end
def find_by_key(key)
@@registrations.each{|t|
return t if t.key.eql?(key)
}
return nil
end
def all
return @@registrations
end
end
extend ClassMethods
def self.included(other)
other.extend( ClassMethods )
end
class RegisteredModule
attr_reader :name,:key,:module_label, :widget_methods
def initialize(name,&block)
@name = name
@key = @name.underscore.singularize
# @module_label = 'rulingcom.errors.init.module_app_noname'
@widget_methods = []
setup_module_app
end
def get_module_app
ModuleApp.find_by(key: @key, title: name) rescue nil
end
def setup_module_app
module_app = get_module_app
module_app = ModuleApp.new(:key=>@key,:title=>name, :widget_methods => @widget_methods) if module_app.nil?
module_app.save(:validate=>false)
end
end
end
end
end