Class: CitizenCodeScripts::Doctor::Check

Inherits:
Object
  • Object
show all
Includes:
Colorize
Defined in:
lib/citizen_code_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.



7
8
9
10
11
12
# File 'lib/citizen_code_scripts/doctor.rb', line 7

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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/citizen_code_scripts/doctor.rb', line 5

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/citizen_code_scripts/doctor.rb', line 5

def name
  @name
end

#problemsObject (readonly)

Returns the value of attribute problems.



5
6
7
# File 'lib/citizen_code_scripts/doctor.rb', line 5

def problems
  @problems
end

#remedyObject (readonly)

Returns the value of attribute remedy.



5
6
7
# File 'lib/citizen_code_scripts/doctor.rb', line 5

def remedy
  @remedy
end

Instance Method Details

#run!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/citizen_code_scripts/doctor.rb', line 14

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: #{fix}\n\n"

    problems << name
  end
end