Class: VivlioStarter::CLI::DeleteCommands::DeleteCommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/delete.rb

Overview

delete コマンドの制御フローを担う実行クラス

オプション解釈・対象解決・削除処理の各責務を分離し、 テスト容易性と保守性を確保している。

Instance Method Summary collapse

Constructor Details

#initialize(options_source, tokens) ⇒ DeleteCommandExecutor

Returns a new instance of DeleteCommandExecutor.

Parameters:

  • options_source (Hash, Object)

    オプション情報

    • Hash: { force: true, verbose: false }
    • Object: #options メソッドで Hash を返すオブジェクト
  • tokens (Array<String>)

    削除対象の指定

    • 章番号: "11" → 11-*.md にマッチ
    • 範囲: "11-13" → 11〜13 番の章すべて
    • ファイル名: "11-install" → 11-install.md


54
55
56
57
58
# File 'lib/vivlio_starter/cli/delete.rb', line 54

def initialize(options_source, tokens)
  @options = DeleteOptions.new(options_source)
  @resolver = TargetResolver.new(tokens)
  @deletion = ChapterDeletion.new(@options)
end

Instance Method Details

#callDeleteSummary

削除処理を実行する

Returns:

  • (DeleteSummary)

    削除した対象の内訳(表示は呼び出し側の責務)

Raises:

  • (SystemExit)

    対象が見つからない場合 exit(1)



64
65
66
67
68
69
# File 'lib/vivlio_starter/cli/delete.rb', line 64

def call
  options.apply_verbose!
  ensure_targets!

  targets.sum(DeleteSummary.none) { |basename| deletion.remove(basename) }
end