Class: VivlioStarter::CLI::Guards::ChapterTargetCheck
- Defined in:
- lib/vivlio_starter/cli/guards/chapter_target_check.rb
Overview
CLI に並べた章指定(vs build 11-install abc)がすべて解決できるかを検証する。
解決できない指定が 1 つでもあれば、何もせずに止める。
解決できたぶんだけ処理を進めると、vs build 11-install abc が「11-install だけ
組んで成功」で終わる——著者は 2 章ぶんできたつもりでいるのに、成果物にも
終了コードにも食い違いが出ない。CLI 引数は設定ファイルと違って「今打った指示」
なので、一部を黙って捨ててよい場面がない。vs lint の作法に揃えている。
検証は指定 1 つずつ行う。範囲(11-13)は複数の章に展開されるため、
まとめて解決すると「どの指定が悪かったか」を著者へ返せなくなる。
Instance Method Summary collapse
-
#initialize(targets) ⇒ ChapterTargetCheck
constructor
A new instance of ChapterTargetCheck.
- #validate ⇒ Object
Constructor Details
#initialize(targets) ⇒ ChapterTargetCheck
Returns a new instance of ChapterTargetCheck.
23 24 25 26 |
# File 'lib/vivlio_starter/cli/guards/chapter_target_check.rb', line 23 def initialize(targets) super() @targets = Array(targets).map(&:to_s).reject { it.strip.empty? } end |
Instance Method Details
#validate ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/vivlio_starter/cli/guards/chapter_target_check.rb', line 28 def validate return [] if @targets.empty? unresolved = @targets.filter_map { unresolved_labels_for(it) } return [] if unresolved.empty? missing, uncataloged = unresolved.partition { it[:reason] == :missing } [missing_violation(missing), uncataloged_violation(uncataloged)].compact end |