2014-04-01 07:10:21 +00:00
|
|
|
#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
|
2014-04-02 12:08:27 +00:00
|
|
|
attr_reader :name,:key,:module_label,:widget_methods
|
2014-04-01 07:10:21 +00:00
|
|
|
|
|
|
|
def initialize(name,&block)
|
|
|
|
@name = name
|
|
|
|
@key = @name.underscore.singularize
|
2014-04-07 09:26:43 +00:00
|
|
|
@side_bar = nil
|
2014-04-02 12:08:27 +00:00
|
|
|
@module_label = @name
|
2014-04-02 06:07:04 +00:00
|
|
|
@widget_methods = []
|
2014-04-02 12:08:27 +00:00
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
2014-04-01 07:10:21 +00:00
|
|
|
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
|
2014-04-02 12:08:27 +00:00
|
|
|
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
|
2014-04-01 07:10:21 +00:00
|
|
|
module_app.save(:validate=>false)
|
|
|
|
end
|
|
|
|
|
2014-04-02 12:08:27 +00:00
|
|
|
%w{data_count module_label category base_url version organization author intro update_info}.each do |field|
|
|
|
|
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_label(name = @name)
|
|
|
|
@module_label = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget_methods(widgets)
|
|
|
|
@widget_methods = widgets
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_widget_methods
|
|
|
|
@widget_methods
|
|
|
|
end
|
|
|
|
|
2014-04-07 09:26:43 +00:00
|
|
|
def get_icon_class
|
|
|
|
@side_bar.get_icon_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def side_bar(&block) #setter for side_bar from init
|
|
|
|
@side_bar = SideBarRegistration::SideBar.new(@name,@key,method(:get_module_app), &block)
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:10:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|