class Aio::ModuleManager
管理,保存各个加载的模块
Attributes
modules[RW]
modules_count[RW]
Public Class Methods
new()
click to toggle source
NOTE modules = {
:module_type // 是cmd, input, output :module_layer_2 // cisco,huawei , style :full_path :klass
# 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
Public Instance Methods
add_module(path, module_type, module_layer_2, reference_name, module_klass)
click to toggle source
将实例化后的模块类放到 modules 中
# 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)
click to toggle source
判断此设备类型的模块是否加载
# File lib/aio/core/module_manager.rb, line 87 def device_type_enable?(device_type) true end
get_module_klass_by_name(reference_name)
click to toggle source
通过参考名获得模块类
# 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)
click to toggle source
通过设备类型获得模块类 返回类型为: 数组
# 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)
click to toggle source
获得指定模块类型 返回类型: Hash
# 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()
click to toggle source
获得所有加载模块的设备类型的字符串型 返回类型为: 数组
# 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={})
click to toggle source
加载一个目录下的所有模块 @param [String] path 目录的路径 @param [Hash] options
# File lib/aio/core/module_manager.rb, line 24 def load_modules(path, options={}) end
module_type_enable?(module_type)
click to toggle source
# 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={})
click to toggle source
# 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