Class: EasyAI::ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/easyai/config/config.rb

Overview

ConfigManager 类负责业务配置逻辑和用户认证

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ConfigManager

Returns a new instance of ConfigManager.



11
12
13
14
15
16
# File 'lib/easyai/config/config.rb', line 11

def initialize(options = {})
  @verbose = options[:verbose] || false
  @tool_type = options[:tool_type]
  @platform = options[:platform]
  @platform_flag = options[:platform_flag] || false
end

Instance Attribute Details

#platformObject (readonly)

Returns the value of attribute platform.



9
10
11
# File 'lib/easyai/config/config.rb', line 9

def platform
  @platform
end

#tool_typeObject (readonly)

Returns the value of attribute tool_type.



9
10
11
# File 'lib/easyai/config/config.rb', line 9

def tool_type
  @tool_type
end

#verboseObject (readonly)

Returns the value of attribute verbose.



9
10
11
# File 'lib/easyai/config/config.rb', line 9

def verbose
  @verbose
end

Class Method Details

.download_user_config(user_name = nil, options = {}) ⇒ Object

类方法兼容接口



19
20
21
22
# File 'lib/easyai/config/config.rb', line 19

def self.download_user_config(user_name = nil, options = {})
  manager = new(options)
  manager.download_user_config(user_name)
end

Instance Method Details

#download_user_config(user_name = nil) ⇒ Object

主要接口:下载用户配置



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/easyai/config/config.rb', line 25

def download_user_config(user_name = nil)
  puts "正在加载配置..." if @verbose
  log_config_info if @verbose

  # 确保配置仓库就绪
  EasyAIConfig.initialize(verbose: @verbose)

  # 获取 index 配置
  users = get_index_config
  return nil unless users
  return nil if users_empty?(users)

  # 获取用户名
  selected_user = user_name || get_username_from_jps
  return handle_user_result(selected_user) unless selected_user.is_a?(String)

  # 处理平台选择
  if @platform_flag && @tool_type == "claude"
    @platform = select_platform_for_user(users, selected_user.strip)
    return nil unless @platform
  end

  # 查找并加载配置
  config_filename = find_user_config(users, selected_user.strip)
  return nil unless config_filename

  puts "✓ 正在为 #{selected_user} 加载配置" if @verbose
  get_user_config_content(config_filename)
end