class WoolenCommon::Middleware::MapCfgManager
Constants
- MERGE_TYPE_ARRAY
- MERGE_TYPE_HASH
- MERGE_TYPE_REPLACE
Attributes
cfg_hash[RW]
merge_type[RW]
Public Class Methods
new(cfg_path,cfg_type='yml',merge_type = MERGE_TYPE_REPLACE)
click to toggle source
# File lib/woolen_common/abstract_middleware/map_cfg_manager.rb, line 10 def initialize(cfg_path,cfg_type='yml',merge_type = MERGE_TYPE_REPLACE) case cfg_type when 'yml' @cfg_hash = YmlCfgManager.load cfg_path else error "不支持的配置文件格式:#{cfg_type}" end @merge_type = merge_type end
Public Instance Methods
add_cfg(cfg_path,cfg_type='yml')
click to toggle source
# File lib/woolen_common/abstract_middleware/map_cfg_manager.rb, line 20 def add_cfg(cfg_path,cfg_type='yml') case cfg_type when 'yml' add_cfg = YmlCfgManager.load cfg_path else add_cfg = {} error "不支持的配置文件格式:#{cfg_type}" end @cfg_hash.merge! add_cfg do |key,old_val,new_val| case @merge_type when MERGE_TYPE_REPLACE ret_val = new_val when MERGE_TYPE_HASH ret_val = {:old_val=>old_val,:new_val=>new_val} when MERGE_TYPE_ARRAY ret_val = [new_val,old_val] else ret_val = old_val end trace "merge key :#{key},the old_val :#{old_val},the new_val :#{new_val},ret_val :#{ret_val}" ret_val end end