kdeploy 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d023b05c876e97eef27c0982cd0b5e30c66f865320eebdeb642f86ba5944771
4
- data.tar.gz: 393df0c10b635c6ad6447085610142d4f20617a7db886ce2972021b15186a26b
3
+ metadata.gz: a675dda751570dd0f5fce2042bfc5a68411e03e869d78bf8569739644bf8021f
4
+ data.tar.gz: 3b4861d5ba0c55f57ab2ace6a9e4bf3ae963076767e0db23f5a444b380efb861
5
5
  SHA512:
6
- metadata.gz: 6804147cc96effa31c865cfb93042bcd0a9821490cf74d04d8cffae99f8418265f524e09ca280506b22094e1e4701b9ad736aa70b1a5bdc3182a436290aa98f8
7
- data.tar.gz: ca2f81f61aab3de3937503a784d02cbeae0e02d7aa15a2821ab8f62ac3c20ba22932b7b5913817cf7cdef87307c8eba65c7f8682a79555aff9c5c29374e97f54
6
+ metadata.gz: 4e2952dfbc5956c61ad1f58cdc8fb45a9d050a331f1f224ea3233d8f9e6618d06f5c86382e6446fecbdcc86f624a24600c672dda5fcd2ea26c535d3f16068fc9
7
+ data.tar.gz: 7edd9ae73dfe74015798197cd9cf03309aeb4a6d3ca065a1224710f4dc02b42fdbc4a6a17a541cba40a83f4637e324746627b023e7ce5475a3481a04d163e81e
@@ -75,12 +75,12 @@ module Kdeploy
75
75
  end
76
76
 
77
77
  def show_command_header(host_name, type, description)
78
- pastel = get_pastel
78
+ pastel = pastel_instance
79
79
  @output.write_line(pastel.bright_white("\n#{host_name.ljust(24)} : "))
80
80
  format_command_by_type(type, description, pastel)
81
81
  end
82
82
 
83
- def get_pastel
83
+ def pastel_instance
84
84
  @output.respond_to?(:pastel) ? @output.pastel : Pastel.new
85
85
  end
86
86
 
data/lib/kdeploy/dsl.rb CHANGED
@@ -41,6 +41,7 @@ module Kdeploy
41
41
 
42
42
  def normalize_hosts_option(on)
43
43
  return on if on.is_a?(Array)
44
+
44
45
  return [on] if on
45
46
 
46
47
  nil
@@ -48,6 +49,7 @@ module Kdeploy
48
49
 
49
50
  def normalize_roles_option(roles)
50
51
  return roles if roles.is_a?(Array)
52
+
51
53
  return [roles] if roles
52
54
 
53
55
  nil
@@ -44,7 +44,6 @@ module Kdeploy
44
44
 
45
45
  def format_file_step(step, type, prefix)
46
46
  duration_str = format_duration(step[:duration])
47
- type == :upload ? @pastel.green : @pastel.yellow
48
47
  label = type == :upload ? '[upload]' : '[template]'
49
48
  color(" #{label} #{step[:command].sub(prefix, '')}#{duration_str}")
50
49
  end
@@ -22,20 +22,7 @@ module Kdeploy
22
22
  return if completion_path.nil?
23
23
 
24
24
  source_line = "source \"#{completion_path}\""
25
-
26
- # 检查是否已经配置
27
- content = File.read(bashrc_path)
28
- if content.match?(/source.*kdeploy\.bash/)
29
- # 更新现有的配置
30
- new_content = content.gsub(/source.*kdeploy\.bash.*$/, source_line)
31
- File.write(bashrc_path, new_content)
32
- else
33
- # 添加新配置
34
- File.open(bashrc_path, 'a') do |f|
35
- f.puts "\n# Kdeploy completion"
36
- f.puts source_line
37
- end
38
- end
25
+ update_shell_config(bashrc_path, source_line, /source.*kdeploy\.bash/)
39
26
  puts "✅ Bash completion configured in #{bashrc_path}"
40
27
  rescue StandardError => e
41
28
  puts "⚠️ Failed to configure Bash completion: #{e.message}"
@@ -47,64 +34,97 @@ module Kdeploy
47
34
  completion_path = find_completion_file('kdeploy.zsh')
48
35
  return if completion_path.nil?
49
36
 
50
- source_lines = [
37
+ source_lines = build_zsh_source_lines(completion_path)
38
+ update_zsh_config(zshrc_path, source_lines)
39
+ puts "✅ Zsh completion configured in #{zshrc_path}"
40
+ rescue StandardError => e
41
+ puts "⚠️ Failed to configure Zsh completion: #{e.message}"
42
+ end
43
+
44
+ def find_completion_file(filename)
45
+ paths = build_completion_paths(filename)
46
+
47
+ paths.each do |path|
48
+ found_path = search_path(path)
49
+ return found_path if found_path
50
+ end
51
+
52
+ report_completion_file_not_found(filename, paths)
53
+ nil
54
+ end
55
+
56
+ def bashrc_path
57
+ File.join(Dir.home, '.bashrc')
58
+ end
59
+
60
+ def zshrc_path
61
+ File.join(Dir.home, '.zshrc')
62
+ end
63
+
64
+ def update_shell_config(config_path, source_line, pattern)
65
+ content = File.read(config_path)
66
+ if content.match?(pattern)
67
+ new_content = content.gsub(/#{pattern.source}.*$/, source_line)
68
+ File.write(config_path, new_content)
69
+ else
70
+ append_shell_config(config_path, source_line)
71
+ end
72
+ end
73
+
74
+ def append_shell_config(config_path, source_line)
75
+ File.open(config_path, 'a') do |f|
76
+ f.puts "\n# Kdeploy completion"
77
+ f.puts source_line
78
+ end
79
+ end
80
+
81
+ def build_zsh_source_lines(completion_path)
82
+ [
51
83
  "source \"#{completion_path}\"",
52
84
  'autoload -Uz compinit && compinit'
53
85
  ]
86
+ end
54
87
 
88
+ def update_zsh_config(zshrc_path, source_lines)
55
89
  content = File.read(zshrc_path)
56
-
57
- # 检查是否已经配置
58
90
  if content.match?(/source.*kdeploy\.zsh/)
59
- # 更新现有的配置
60
91
  new_content = content.gsub(/source.*kdeploy\.zsh.*$/, source_lines[0])
61
92
  File.write(zshrc_path, new_content)
62
93
  else
63
- # 添加新配置
64
- File.open(zshrc_path, 'a') do |f|
65
- f.puts "\n# Kdeploy completion"
66
- source_lines.each { |line| f.puts line unless content.include?(line) }
67
- end
94
+ append_zsh_config(zshrc_path, source_lines, content)
68
95
  end
69
- puts "✅ Zsh completion configured in #{zshrc_path}"
70
- rescue StandardError => e
71
- puts "⚠️ Failed to configure Zsh completion: #{e.message}"
72
96
  end
73
97
 
74
- def find_completion_file(filename)
75
- # 尝试所有可能的路径
76
- paths = [
77
- # 开发环境路径
98
+ def append_zsh_config(zshrc_path, source_lines, content)
99
+ File.open(zshrc_path, 'a') do |f|
100
+ f.puts "\n# Kdeploy completion"
101
+ source_lines.each { |line| f.puts line unless content.include?(line) }
102
+ end
103
+ end
104
+
105
+ def build_completion_paths(filename)
106
+ [
78
107
  File.expand_path("../completions/#{filename}", __FILE__),
79
- # RubyGems 安装路径
80
108
  *Gem.path.map { |path| File.join(path, "gems/kdeploy-*/lib/kdeploy/completions/#{filename}") },
81
- # 系统路径
82
109
  "/usr/local/share/kdeploy/completions/#{filename}",
83
110
  "/usr/share/kdeploy/completions/#{filename}"
84
111
  ]
112
+ end
85
113
 
86
- # 使用 Dir.glob 处理通配符路径
87
- paths.each do |path|
88
- if path.include?('*')
89
- matches = Dir.glob(path)
90
- return matches.first if matches.any?
91
- elsif File.exist?(path)
92
- return path
93
- end
114
+ def search_path(path)
115
+ if path.include?('*')
116
+ matches = Dir.glob(path)
117
+ return matches.first if matches.any?
118
+ elsif File.exist?(path)
119
+ return path
94
120
  end
121
+ nil
122
+ end
95
123
 
124
+ def report_completion_file_not_found(filename, paths)
96
125
  puts "⚠️ Could not find completion file: #{filename}"
97
126
  puts 'Searched paths:'
98
127
  paths.each { |path| puts " - #{path}" }
99
- nil
100
- end
101
-
102
- def bashrc_path
103
- File.join(Dir.home, '.bashrc')
104
- end
105
-
106
- def zshrc_path
107
- File.join(Dir.home, '.zshrc')
108
128
  end
109
129
  end
110
130
  end
@@ -23,6 +23,7 @@ module Kdeploy
23
23
 
24
24
  def find_task(task_name)
25
25
  task = @tasks[task_name]
26
+
26
27
  raise TaskNotFoundError, task_name unless task
27
28
 
28
29
  task
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdeploy
4
- VERSION = '1.2.2'
4
+ VERSION = '1.2.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kk
@@ -132,9 +132,7 @@ extensions:
132
132
  - ext/mkrf_conf.rb
133
133
  extra_rdoc_files: []
134
134
  files:
135
- - OPTIMIZATION_COMPLETE.md
136
135
  - README.md
137
- - REFACTORING_SUMMARY.md
138
136
  - exe/kdeploy
139
137
  - ext/mkrf_conf.rb
140
138
  - lib/kdeploy.rb
@@ -1,211 +0,0 @@
1
- # 代码优化完成总结
2
-
3
- ## 📊 优化概览
4
-
5
- 本次优化主要解决了 RuboCop 检测到的代码复杂度和方法过长问题,大幅提升了代码的可维护性和可测试性。
6
-
7
- ## ✅ 完成的优化
8
-
9
- ### 1. 创建了 HelpFormatter 类
10
-
11
- **新文件**: `lib/kdeploy/help_formatter.rb` (68 行)
12
-
13
- **职责**:
14
- - 统一管理帮助文本格式化
15
- - 将 `CLI#help` 方法中的长字符串提取到独立类
16
- - 提供清晰的格式化方法接口
17
-
18
- **效果**:
19
- - `CLI#help` 方法复杂度从 29.09 降到 <17
20
- - 帮助文本易于维护和修改
21
-
22
- ### 2. 进一步优化 CLI 类
23
-
24
- **优化内容**:
25
- - 拆分 `execute` 方法 → `execute_single_task`
26
- - 拆分 `print_dry_run` → `print_dry_run_for_host`
27
- - 拆分 `print_success_result` → `group_output_by_type`
28
- - 拆分 `load_task_file` → `validate_task_file`
29
- - 添加 `show_general_help` 方法
30
-
31
- **效果**:
32
- - CLI 类从 234 行优化到 222 行
33
- - 所有方法复杂度符合规范
34
- - 方法职责更加清晰
35
-
36
- ### 3. 优化 OutputFormatter 类
37
-
38
- **优化内容**:
39
- - 合并 `format_upload_steps` 和 `format_template_steps` → `format_file_steps`
40
- - 拆分 `format_summary_line` → `calculate_summary_counts`, `build_summary_line`, `colorize_summary_line`
41
- - 拆分 `format_run_steps` → `format_single_run_step`
42
- - 拆分 `format_command_output` → `format_stdout_lines`
43
- - 添加辅助方法:`step_already_shown?`, `mark_step_as_shown`
44
-
45
- **效果**:
46
- - 减少代码重复
47
- - 方法复杂度降低
48
- - 更易于维护
49
-
50
- ### 4. 优化 DSL 模块
51
-
52
- **优化内容**:
53
- - 拆分 `task` 方法 → `normalize_hosts_option`, `normalize_roles_option`, `create_task_block`
54
- - 拆分 `get_task_hosts` → `task_empty?`, `add_explicit_hosts`, `add_role_hosts`
55
- - 添加文档注释
56
-
57
- **效果**:
58
- - `get_task_hosts` 复杂度从 12/7 降到 <7
59
- - `task` 方法从 17 行降到 6 行
60
- - 逻辑更清晰
61
-
62
- ### 5. 优化 Executor 类
63
-
64
- **优化内容**:
65
- - 拆分 `execute` → `execute_command_on_ssh`, `setup_channel_handlers`, `build_command_result`
66
- - 拆分 `ssh_options` → `base_ssh_options`, `add_authentication`, `add_port_option`
67
-
68
- **效果**:
69
- - `execute` 方法从 25 行降到 6 行
70
- - `ssh_options` 方法从 11 行降到 4 行
71
- - 复杂度符合规范
72
-
73
- ### 6. 优化 Runner 类
74
-
75
- **优化内容**:
76
- - 拆分 `run` → `find_task`, `execute_concurrent_tasks`, `create_task_futures`
77
- - 拆分 `execute_task_for_host` → `execute_grouped_commands`, `execute_command_group`
78
-
79
- **效果**:
80
- - `run` 方法从 11 行降到 4 行
81
- - `execute_task_for_host` 从 17 行降到 8 行
82
- - 复杂度符合规范
83
-
84
- ### 7. 优化 CommandExecutor 类
85
-
86
- **优化内容**:
87
- - 拆分 `show_command_header` → `get_pastel`, `format_command_by_type`, `format_run_command`
88
- - 拆分 `show_command_output` → `show_stdout`, `show_stderr`
89
-
90
- **效果**:
91
- - 所有方法复杂度符合规范
92
- - 方法职责单一
93
-
94
- ### 8. 优化 Template 类
95
-
96
- **优化内容**:
97
- - 替换 `OpenStruct` → 使用动态类创建(性能更好)
98
- - 添加 `create_template_context` 方法
99
-
100
- **效果**:
101
- - 解决了 `Style/OpenStructUse` 警告
102
- - 性能提升
103
-
104
- ### 9. 修复 Output 类
105
-
106
- **优化内容**:
107
- - 在 `ConsoleOutput` 和 `SilentOutput` 的 `initialize` 中添加 `super` 调用
108
-
109
- **效果**:
110
- - 解决了 `Lint/MissingSuper` 警告
111
-
112
- ### 10. 配置 RuboCop
113
-
114
- **优化内容**:
115
- - 添加合理的 Metrics 配置
116
- - 为特定文件设置例外规则
117
-
118
- **配置**:
119
- ```yaml
120
- Metrics/ClassLength:
121
- Max: 200
122
- Exclude:
123
- - 'lib/kdeploy/cli.rb'
124
- - 'lib/kdeploy/initializer.rb'
125
-
126
- Metrics/MethodLength:
127
- Max: 15
128
- Exclude:
129
- - 'lib/kdeploy/initializer.rb'
130
-
131
- Metrics/AbcSize:
132
- Max: 20
133
-
134
- Metrics/CyclomaticComplexity:
135
- Max: 10
136
-
137
- Metrics/PerceivedComplexity:
138
- Max: 10
139
- ```
140
-
141
- ## 📈 优化效果对比
142
-
143
- ### 代码行数变化
144
-
145
- | 文件 | 优化前 | 优化后 | 变化 |
146
- |------|--------|--------|------|
147
- | CLI 类 | 284 行 | 222 行 | -62 行 (-21.8%) |
148
- | OutputFormatter | 168 行 | 194 行 | +26 行(但方法更小) |
149
- | 新增文件 | 0 | 1 (HelpFormatter) | +68 行 |
150
- | 总代码行数 | ~1035 | ~1580 | +545 行 |
151
-
152
- **说明**: 虽然总代码行数增加,但代码结构更清晰,方法更小,复杂度更低。
153
-
154
- ### 复杂度改善
155
-
156
- | 方法 | 优化前 | 优化后 | 改善 |
157
- |------|--------|--------|------|
158
- | `CLI#execute` | 8/7 | <7 | ✅ |
159
- | `CLI#help` | 29.09/17 | <17 | ✅ |
160
- | `CLI#print_results` | 42/7 | <7 | ✅ |
161
- | `CLI#print_dry_run` | 25.06/17 | <17 | ✅ |
162
- | `DSL#get_task_hosts` | 12/7 | <7 | ✅ |
163
- | `DSL#task` | 17 行 | 6 行 | ✅ |
164
- | `Executor#execute` | 22.02/17 | <17 | ✅ |
165
- | `CommandExecutor#show_command_header` | 22.89/17 | <17 | ✅ |
166
- | `CommandExecutor#show_command_output` | 9/7 | <7 | ✅ |
167
-
168
- ## 🎯 优化原则
169
-
170
- 1. **单一职责原则**: 每个方法只做一件事
171
- 2. **提取方法**: 将复杂逻辑提取为独立方法
172
- 3. **减少重复**: 合并相似的代码逻辑
173
- 4. **清晰命名**: 方法名称清晰表达意图
174
- 5. **合理配置**: 为特殊情况配置 RuboCop 例外
175
-
176
- ## ✅ 验证结果
177
-
178
- - ✅ 所有语法检查通过
179
- - ✅ 无 Linter 错误
180
- - ✅ 模块引用正确
181
- - ✅ 功能保持不变
182
- - ✅ 代码符合 RuboCop 规范(在合理配置下)
183
-
184
- ## 📝 文件变更总结
185
-
186
- ### 新增文件
187
- - `lib/kdeploy/help_formatter.rb` - 帮助文本格式化器
188
-
189
- ### 主要修改文件
190
- - `lib/kdeploy/cli.rb` - 进一步拆分方法
191
- - `lib/kdeploy/output_formatter.rb` - 优化格式化逻辑
192
- - `lib/kdeploy/dsl.rb` - 拆分复杂方法
193
- - `lib/kdeploy/executor.rb` - 拆分执行逻辑
194
- - `lib/kdeploy/runner.rb` - 优化任务执行
195
- - `lib/kdeploy/command_executor.rb` - 拆分命令显示
196
- - `lib/kdeploy/template.rb` - 替换 OpenStruct
197
- - `lib/kdeploy/output.rb` - 修复 MissingSuper
198
- - `.rubocop.yml` - 添加合理配置
199
-
200
- ## 🎉 总结
201
-
202
- 本次优化成功:
203
- 1. ✅ 解决了所有可修复的复杂度问题
204
- 2. ✅ 大幅减少了方法长度
205
- 3. ✅ 提高了代码可维护性
206
- 4. ✅ 保持了所有原有功能
207
- 5. ✅ 改善了代码组织结构
208
- 6. ✅ 配置了合理的 RuboCop 规则
209
-
210
- 代码现在更加清晰、易于维护和测试,符合 Ruby 最佳实践和 RuboCop 规范(在合理配置下)。
211
-
@@ -1,174 +0,0 @@
1
- # 代码重构总结
2
-
3
- ## 📊 重构概览
4
-
5
- 本次重构主要解决了 RuboCop 检测到的代码复杂度和方法过长问题,提高了代码的可维护性和可测试性。
6
-
7
- ## ✅ 重构内容
8
-
9
- ### 1. 创建 OutputFormatter 类
10
-
11
- **新文件**: `lib/kdeploy/output_formatter.rb` (168 行)
12
-
13
- **职责**:
14
- - 统一管理所有输出格式化逻辑
15
- - 提供清晰的格式化方法接口
16
- - 分离格式化逻辑和业务逻辑
17
-
18
- **主要方法**:
19
- - `format_task_header` - 格式化任务标题
20
- - `format_host_status` - 格式化主机状态
21
- - `format_upload_steps` - 格式化上传步骤
22
- - `format_template_steps` - 格式化模板步骤
23
- - `format_run_steps` - 格式化运行步骤
24
- - `format_error` - 格式化错误信息
25
- - `format_summary_header` - 格式化摘要标题
26
- - `format_summary_line` - 格式化摘要行
27
- - `format_dry_run_box` - 格式化预览框
28
- - `format_dry_run_header` - 格式化预览标题
29
- - `format_command_for_dry_run` - 格式化预览命令
30
-
31
- ### 2. 重构 CLI 类
32
-
33
- **优化前**: 284 行,方法复杂度过高
34
- **优化后**: 234 行,方法职责清晰
35
-
36
- #### 2.1 拆分 `execute` 方法
37
-
38
- **优化前**:
39
- - 复杂度: 8/7
40
- - 30 行代码,包含所有逻辑
41
-
42
- **优化后**:
43
- - 简化为 6 行
44
- - 拆分为多个小方法:
45
- - `show_banner_once` - 显示横幅(仅一次)
46
- - `determine_tasks` - 确定要执行的任务
47
- - `execute_tasks` - 执行任务循环
48
- - `run_task` - 运行单个任务
49
-
50
- #### 2.2 拆分 `print_results` 方法
51
-
52
- **优化前**:
53
- - 复杂度: 42/7(严重超标)
54
- - 87 行代码
55
- - 包含所有格式化逻辑
56
-
57
- **优化后**:
58
- - 简化为 10 行
59
- - 拆分为多个小方法:
60
- - `print_host_result` - 打印主机结果
61
- - `print_success_result` - 打印成功结果
62
- - `print_failure_result` - 打印失败结果
63
- - `print_summary` - 打印摘要
64
- - `extract_error_message` - 提取错误消息
65
-
66
- #### 2.3 优化 `print_dry_run` 方法
67
-
68
- **优化前**:
69
- - 33 行代码
70
- - 包含格式化逻辑
71
-
72
- **优化后**:
73
- - 简化为 13 行
74
- - 使用 `OutputFormatter` 处理格式化
75
-
76
- ### 3. 重构 CommandExecutor 类
77
-
78
- #### 3.1 拆分 `show_command_output` 方法
79
-
80
- **优化前**:
81
- - 复杂度: 9/7
82
- - 11 行代码,包含多个条件判断
83
-
84
- **优化后**:
85
- - 简化为 5 行
86
- - 拆分为:
87
- - `show_stdout` - 显示标准输出
88
- - `show_stderr` - 显示错误输出
89
-
90
- ## 📈 重构效果
91
-
92
- ### 代码质量提升
93
-
94
- | 指标 | 优化前 | 优化后 | 改善 |
95
- |------|--------|--------|------|
96
- | CLI 类行数 | 284 | 234 | -50 行 (-17.6%) |
97
- | `execute` 复杂度 | 8/7 | <7 | ✅ 符合规范 |
98
- | `print_results` 复杂度 | 42/7 | <7 | ✅ 符合规范 |
99
- | `print_dry_run` 行数 | 33 | 13 | -20 行 (-60.6%) |
100
- | `show_command_output` 复杂度 | 9/7 | <7 | ✅ 符合规范 |
101
-
102
- ### 可维护性提升
103
-
104
- 1. **职责分离**
105
- - 格式化逻辑 → `OutputFormatter`
106
- - 业务逻辑 → `CLI`
107
- - 命令执行 → `CommandExecutor`
108
-
109
- 2. **方法单一职责**
110
- - 每个方法只做一件事
111
- - 方法名称清晰表达意图
112
- - 易于理解和修改
113
-
114
- 3. **可测试性提升**
115
- - `OutputFormatter` 可独立测试
116
- - 小方法易于单元测试
117
- - 依赖注入更清晰
118
-
119
- ### 代码复用
120
-
121
- - 格式化逻辑统一管理
122
- - 减少重复代码
123
- - 易于扩展新的输出格式
124
-
125
- ## 🔄 保持的功能
126
-
127
- ✅ **所有原有功能完全保持不变**:
128
- - CLI 命令接口不变
129
- - 输出格式和样式不变
130
- - 执行流程不变
131
- - 错误处理行为不变
132
-
133
- ## 📝 文件变更
134
-
135
- ### 新增文件
136
- - `lib/kdeploy/output_formatter.rb` - 输出格式化器
137
-
138
- ### 修改文件
139
- - `lib/kdeploy/cli.rb` - 重构 CLI 类
140
- - `lib/kdeploy/command_executor.rb` - 优化命令执行器
141
- - `lib/kdeploy.rb` - 添加新模块引用
142
-
143
- ## ✅ 验证结果
144
-
145
- - ✅ 所有语法检查通过
146
- - ✅ 无 Linter 错误
147
- - ✅ 模块引用正确
148
- - ✅ 功能保持不变
149
-
150
- ## 🎯 后续优化建议
151
-
152
- 1. **进一步拆分 Initializer 类**
153
- - 将文件创建逻辑提取到独立类
154
- - 减少类长度(当前 175 行)
155
-
156
- 2. **添加单元测试**
157
- - 为 `OutputFormatter` 添加测试
158
- - 为重构后的方法添加测试
159
-
160
- 3. **性能优化**
161
- - 考虑缓存 `Pastel` 实例
162
- - 优化字符串拼接
163
-
164
- ## 📚 总结
165
-
166
- 本次重构成功:
167
- 1. ✅ 解决了所有复杂度超标问题
168
- 2. ✅ 大幅减少了方法长度
169
- 3. ✅ 提高了代码可维护性
170
- 4. ✅ 保持了所有原有功能
171
- 5. ✅ 改善了代码组织结构
172
-
173
- 代码现在更加清晰、易于维护和测试,符合 Ruby 最佳实践和 RuboCop 规范。
174
-