Class: DocktorRails::Preflight::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/docktor_rails/preflight/runner.rb

Constant Summary collapse

DEFAULT_CHECKS =
[
  Checks::ComposeFilePresent,
  Checks::ComposeBuildPaths,
  Checks::ComposeEnvFilePresent,
  Checks::ComposeEntrypointSanity,
  Checks::ComposeEntrypointExec,
  Checks::ShellScriptsCrlf,
  Checks::ComposeHealthchecks,
  Checks::ComposePlatformRisk,
  Checks::RailsMasterKeyRequired
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, checks: DEFAULT_CHECKS) ⇒ Runner

Returns a new instance of Runner.



30
31
32
33
# File 'lib/docktor_rails/preflight/runner.rb', line 30

def initialize(root: Dir.pwd, checks: DEFAULT_CHECKS)
  @root = root
  @checks = checks
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/docktor_rails/preflight/runner.rb', line 35

def run
  platform = Platform.detect
  ctx = { root: @root, platform: platform }

  results = @checks.map do |check_class|
    check_class.new.run(ctx)
  end

  summary = {
    pass: results.count(&:pass?),
    warn: results.count(&:warn?),
    fail: results.count(&:fail?)
  }

  status = if summary[:fail].positive?
    :fail
  elsif summary[:warn].positive?
    :warn
  else
    :pass
  end

  {
    root: @root,
    platform: platform,
    status: status,
    summary: summary,
    checks: results
  }
end