Class: VivlioStarter::CLI::Guards::ConfigValidityCheck

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/vivlio_starter/cli/guards/config_validity_check.rb

Overview

必須 YAML が存在し、かつ妥当な YAML として解析できるかを検証する。 存在のみを見る CatalogFileCheck より厳格(破損も検出する)。 doctor は diagnose の結果(欠落/破損/正常)を復元判断の根拠として共有する (doctor-restore-and-plugin-tools-spec.md §4)。

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: Common::REQUIRED_YAML_FILES) ⇒ ConfigValidityCheck

Returns a new instance of ConfigValidityCheck.

Parameters:

  • paths (Array<String>) (defaults to: Common::REQUIRED_YAML_FILES)

    検証対象(既定: Common::REQUIRED_YAML_FILES)



14
15
16
17
# File 'lib/vivlio_starter/cli/guards/config_validity_check.rb', line 14

def initialize(paths: Common::REQUIRED_YAML_FILES)
  @paths = paths
  super()
end

Class Method Details

.diagnose(path) ⇒ Array(Symbol, String|nil)

1 ファイルの状態を判定する。Check(Guard 層)と doctor(復元層)が 同じ判定を使うための共有入口(doctor 専用に YAML 検証を再実装しない)。

Returns:

  • (Array(Symbol, String|nil))

    [:ok | :missing | :corrupt, 詳細メッセージ]



25
26
27
28
29
30
31
32
33
34
# File 'lib/vivlio_starter/cli/guards/config_validity_check.rb', line 25

def self.diagnose(path)
  return [:missing, nil] unless File.file?(path)

  case YAML.safe_load(File.read(path, encoding: 'utf-8'), aliases: true)
  in Hash | Array then [:ok, nil]
  else [:corrupt, '内容が空、または YAML の構造になっていません']
  end
rescue StandardError => e
  [:corrupt, e.message]
end

Instance Method Details

#validateArray<Violation>

Returns:



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

def validate = @paths.filter_map { violation_for(it) }