refactor: YAGNI/DRY に沿って news.rake のコードを共通化 #1760
Merged
+72
−118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概要
lib/tasks/news.rakeの可読性と保守性を向上させるYAGNI/DRY原則に基づく包括的リファクタリング🎯 主要改善
1. 条件分岐の簡素化(YAGNI原則)
if/elsifに統一existing_item.nil?での明確な新規判定2. 定数による設定集約(DRY原則)
NEWS_YAML_PATH: YAMLファイルパスを一元管理NEWS_LOG_PATH: ログファイルパスを一元管理3. タスク間の変数名統一
fetchタスク:created_items,updated_itemsupsertタスク:created_count,updated_countentries→news_items: より意図が明確attrs→item: 簡潔で統一感のある命名4. コード品質の向上
sorted_items等)を削除itパラメータを活用📊 改善効果
if/elsif✅ 検証済み
bin/rails news:fetchの結果に変更なしdb/news.ymlが正しく保持されることを確認🔧 技術的詳細
適用原則
変更サマリー
lib/tasks/news.rake📈 長期的メリット
🚀 実装アプローチ
段階的リファクタリングにより安全性を確保:
各段階でテストを実行し、既存動作の維持を確認しました。