class Aid::Scripts::Doctor::Check

Attributes

command[R]
name[R]
problems[R]
remedy[R]

Public Class Methods

new(name:, command:, remedy:) click to toggle source
# File lib/aid/scripts/doctor.rb, line 113
def initialize(name:, command:, remedy:)
  @name = name
  @command = command
  @remedy = remedy.is_a?(Remedy) ? remedy : Remedy.new(remedy)
  @problems = []
  @checked_once = false
end

Public Instance Methods

run!() click to toggle source
# File lib/aid/scripts/doctor.rb, line 121
def run!
  print "Checking: #{name}... "

  success = run_command

  if success
    puts 'OK'
  else
    puts colorize(:error, 'F')

    if @checked_once || !remedy.auto_fixable?
      puts "\n  To fix: #{remedy}\n\n"
      problems << name
    elsif remedy.auto_fixable?
      @checked_once = true

      puts '==> attempting autofix'
      remedy.auto_fix!
      puts '==> retrying check'
      run!
    end
  end
end

Private Instance Methods

run_command() click to toggle source
# File lib/aid/scripts/doctor.rb, line 147
def run_command
  if command.respond_to?(:call)
    command.call
  else
    system "#{command} > /dev/null 2>&1"
  end
end