Module: VivlioStarter::CLI::Guards::Guard

Defined in:
lib/vivlio_starter/cli/guards.rb

Overview

コマンド冒頭で Check 群をまとめて実行する入口

Class Method Summary collapse

Class Method Details

.join_detail(detail) ⇒ Object

Common.format_detail は改行区切りの String を期待するため、 Check が行の配列で detail を返した場合はここで連結する



79
# File 'lib/vivlio_starter/cli/guards.rb', line 79

def join_detail(detail) = detail.is_a?(Array) ? detail.join("\n") : detail

.run!(*checks) ⇒ Object

全 Check を実行し、違反を 🔴(error)/ 🟡(warn)でログ出力する。

Parameters:

  • checks (Array<BaseCheck>)

    実行する Check 群

Raises:

  • (GuardError)

    :error 違反が1件以上あれば送出(本処理に入らせない)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vivlio_starter/cli/guards.rb', line 54

def run!(*checks)
  violations = checks.flat_map(&:validate)
  warns, errors = violations.partition(&:warn?)

  warns.each  { Common.log_warn(it.message, detail: join_detail(it.detail)) }
  errors.each { Common.log_error(it.message, detail: join_detail(it.detail)) }

  # 🟡 警告は停止させないため、そのままでは preflight の最終判定に載らない
  # (発生源次第で最終行が変わる非対称の解消・preflight-chapter-summary-spec.md §0-2)。
  # Guard は特定の章に紐付かない横断的な検査なので chapter は nil のままにする。
  # :error は GuardError で即停止しサマリーへ到達しないため記録しない。
  warns.each do |violation|
    PreProcessCommands::IssueRegistry.record(
      severity: :warn, category: :guard, message: violation.message
    )
  end

  return if errors.empty?

  raise GuardError,
        "前提条件を満たしていません(エラー #{errors.size} 件 / 警告 #{warns.size} 件)"
end