Class: Aio::ModuleManager
- Inherits:
-
Object
- Object
- Aio::ModuleManager
- Includes:
- Ui::Verbose
- Defined in:
- lib/aio/core/module_manager.rb
Overview
管理,保存各个加载的模块
Instance Attribute Summary collapse
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#modules_count ⇒ Object
Returns the value of attribute modules_count.
Instance Method Summary collapse
-
#add_module(path, module_type, module_layer_2, reference_name, module_klass) ⇒ Object
将实例化后的模块类放到 modules 中.
-
#device_type_enable?(device_type) ⇒ Boolean
判断此设备类型的模块是否加载.
-
#get_module_klass_by_name(reference_name) ⇒ Object
通过参考名获得模块类.
-
#get_modules_by_device_type(device_type) ⇒ Object
通过设备类型获得模块类 返回类型为: 数组.
-
#get_modules_by_type(type) ⇒ Object
获得指定模块类型 返回类型: Hash.
-
#get_modules_device_type_to_s ⇒ Object
获得所有加载模块的设备类型的字符串型 返回类型为: 数组.
-
#initialize ⇒ ModuleManager
constructor
:klass.
-
#load_modules(path, options = {}) ⇒ Object
加载一个目录下的所有模块.
- #module_type_enable?(module_type) ⇒ Boolean
- #notify(opts = {}) ⇒ Object
Methods included from Ui::Verbose
#clear_line, #print_error, #print_good, #progress_bar
Constructor Details
#initialize ⇒ ModuleManager
:klass
13 14 15 16 17 18 19 |
# File 'lib/aio/core/module_manager.rb', line 13 def initialize # self.module_info_by_path = {} # self.module_load_error_by_path = {} # self.module_paths = [] self.modules = {} self.modules_count = {} end |
Instance Attribute Details
#modules ⇒ Object
Returns the value of attribute modules.
4 5 6 |
# File 'lib/aio/core/module_manager.rb', line 4 def modules @modules end |
#modules_count ⇒ Object
Returns the value of attribute modules_count.
4 5 6 |
# File 'lib/aio/core/module_manager.rb', line 4 def modules_count @modules_count end |
Instance Method Details
#add_module(path, module_type, module_layer_2, reference_name, module_klass) ⇒ Object
将实例化后的模块类放到 modules 中
28 29 30 31 32 33 34 35 |
# File 'lib/aio/core/module_manager.rb', line 28 def add_module(path, module_type, module_layer_2, reference_name, module_klass) modules[reference_name] = {:module_type => module_type, :module_layer_2 => module_layer_2, :full_path => path, :klass => module_klass } end |
#device_type_enable?(device_type) ⇒ Boolean
判断此设备类型的模块是否加载
87 88 89 |
# File 'lib/aio/core/module_manager.rb', line 87 def device_type_enable?(device_type) true end |
#get_module_klass_by_name(reference_name) ⇒ Object
通过参考名获得模块类
102 103 104 105 106 107 108 109 |
# File 'lib/aio/core/module_manager.rb', line 102 def get_module_klass_by_name(reference_name) begin self.modules[reference_name][:klass] rescue Exception print_error "未找到指定模块: #{reference_name}" exit 0 end end |
#get_modules_by_device_type(device_type) ⇒ Object
通过设备类型获得模块类返回类型为: 数组
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aio/core/module_manager.rb', line 55 def get_modules_by_device_type(device_type) return_array = [] device_type = device_type.to_s modules.each_pair do |_, m| if m[:module_type] != "cmd" next end type = m[:module_layer_2] if device_type == type return_array << m[:klass] end end return return_array end |
#get_modules_by_type(type) ⇒ Object
获得指定模块类型返回类型: Hash
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aio/core/module_manager.rb', line 39 def get_modules_by_type(type) return_hash = {} type = type.to_s modules.each_pair do |n, m| if m[:module_type] != type next end return_hash[n] = m end return return_hash end |
#get_modules_device_type_to_s ⇒ Object
获得所有加载模块的设备类型的字符串型返回类型为: 数组
75 76 77 78 79 80 81 82 83 |
# File 'lib/aio/core/module_manager.rb', line 75 def get_modules_device_type_to_s return_array = [] modules_count["cmd"].keys.each do |key| return_array << key.to_s end return return_array end |
#load_modules(path, options = {}) ⇒ Object
加载一个目录下的所有模块
24 25 |
# File 'lib/aio/core/module_manager.rb', line 24 def load_modules(path, ={}) end |
#module_type_enable?(module_type) ⇒ Boolean
91 92 93 |
# File 'lib/aio/core/module_manager.rb', line 91 def module_type_enable?(module_type) ["cmd", "input", "output", "special", "description"].include?(module_type) end |
#notify(opts = {}) ⇒ Object
95 96 97 98 99 |
# File 'lib/aio/core/module_manager.rb', line 95 def notify(opts={}) if opts[:count_by_module_type] @modules_count = opts[:count_by_module_type] end end |