Class: Kdep::CheckRunner
- Inherits:
-
Object
- Object
- Kdep::CheckRunner
- Defined in:
- lib/kdep/check_runner.rb
Overview
Runs declarative preflight validators from app.yml’s ‘check:` list. Each entry is `cmd: <shell-string>` plus optional `inputs: [paths]`. Paths are resolved via PathResolver. The full invocation is `sh -c “<cmd> <resolved_inputs…>”`. Any non-zero exit halts the pipeline.
Defined Under Namespace
Classes: Error
Class Attribute Summary collapse
-
.runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
-
#initialize(checks:, path_resolver:, ui:) ⇒ CheckRunner
constructor
A new instance of CheckRunner.
- #run! ⇒ Object
Constructor Details
#initialize(checks:, path_resolver:, ui:) ⇒ CheckRunner
Returns a new instance of CheckRunner.
17 18 19 20 21 |
# File 'lib/kdep/check_runner.rb', line 17 def initialize(checks:, path_resolver:, ui:) @checks = checks || [] @resolver = path_resolver @ui = ui end |
Class Attribute Details
.runner ⇒ Object
Returns the value of attribute runner.
13 14 15 |
# File 'lib/kdep/check_runner.rb', line 13 def runner @runner end |
Instance Method Details
#run! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kdep/check_runner.rb', line 23 def run! return true if @checks.empty? @checks.each do |entry| cmd = entry["cmd"].to_s raise Error, "check entry missing 'cmd'" if cmd.empty? inputs = Array(entry["inputs"]).map { |p| @resolver.resolve(p, warn_on_fallback: true) } # Shell-quote each input so paths with spaces survive. quoted_inputs = inputs.compact.map { |p| shell_quote(p) } full_cmd = ([cmd] + quoted_inputs).join(" ") @ui.info("check: #{full_cmd}") stdout, stderr, status = self.class.runner.call(full_cmd) unless status.success? @ui.error("check failed: #{full_cmd}") @ui.error(stderr.strip) unless stderr.strip.empty? @ui.error(stdout.strip) unless stdout.strip.empty? raise Error, "preflight check failed: #{full_cmd}" end end true end |