Class: Aid::Scripts::Doctor::Check

Inherits:
Object
  • Object
show all
Includes:
Colorize
Defined in:
lib/aid/scripts/doctor.rb

Constant Summary

Constants included from Colorize

Colorize::COLOR_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colorize

#colorize, included

Constructor Details

#initialize(name:, command:, remedy:) ⇒ Check

Returns a new instance of Check.



9
10
11
12
13
14
# File 'lib/aid/scripts/doctor.rb', line 9

def initialize(name:, command:, remedy:)
  @name = name
  @command = command
  @remedy = remedy
  @problems = []
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/aid/scripts/doctor.rb', line 7

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/aid/scripts/doctor.rb', line 7

def name
  @name
end

#problemsObject (readonly)

Returns the value of attribute problems.



7
8
9
# File 'lib/aid/scripts/doctor.rb', line 7

def problems
  @problems
end

#remedyObject (readonly)

Returns the value of attribute remedy.



7
8
9
# File 'lib/aid/scripts/doctor.rb', line 7

def remedy
  @remedy
end

Instance Method Details

#run!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aid/scripts/doctor.rb', line 16

def run!
  print "Checking: #{name}... "

  success = if command.respond_to?(:call)
    command.call
  else
    system "#{command} > /dev/null 2>&1"
  end

  if success
    puts 'OK'
  else
    print colorize(:error, 'F')
    fix = remedy.respond_to?(:join) ? remedy.join(" ") : remedy
    puts "\n  To fix: #{colorize(:command, fix)}\n\n"

    problems << name
  end
end