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.



113
114
115
116
117
118
119
# 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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



111
112
113
# File 'lib/aid/scripts/doctor.rb', line 111

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



111
112
113
# File 'lib/aid/scripts/doctor.rb', line 111

def name
  @name
end

#problemsObject (readonly)

Returns the value of attribute problems.



111
112
113
# File 'lib/aid/scripts/doctor.rb', line 111

def problems
  @problems
end

#remedyObject (readonly)

Returns the value of attribute remedy.



111
112
113
# File 'lib/aid/scripts/doctor.rb', line 111

def remedy
  @remedy
end

Instance Method Details

#run!Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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