Class: Aid::Scripts::Doctor

Inherits:
Aid::Script show all
Defined in:
lib/aid/scripts/doctor.rb

Defined Under Namespace

Classes: Check, CommandRemedy, Remedy

Constant Summary

Constants included from Colorize

Colorize::COLOR_CODES

Instance Attribute Summary

Attributes inherited from Aid::Script

#argv

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Aid::Script

#description, #exit_with_help!, #help, name, #project_root, run, #step, #system!, #within_dir

Methods included from Inheritable

included

Methods included from Colorize

colorize, included

Constructor Details

#initialize(*args) ⇒ Doctor

Returns a new instance of Doctor.



14
15
16
17
# File 'lib/aid/scripts/doctor.rb', line 14

def initialize(*args)
  super
  @checks = []
end

Class Method Details

.descriptionObject



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

def self.description
  'Checks the health of your development environment'
end

.helpObject



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

def self.help
  'doctor - helps you diagnose any setup issues with this application'
end

Instance Method Details

#check(**options) ⇒ Object



19
20
21
22
23
24
# File 'lib/aid/scripts/doctor.rb', line 19

def check(**options)
  check = Check.new(options)
  @checks << check

  check.run!
end

#command(cmd) ⇒ Object



59
60
61
# File 'lib/aid/scripts/doctor.rb', line 59

def command(cmd)
  CommandRemedy.new(cmd)
end

#exit_codeObject



55
56
57
# File 'lib/aid/scripts/doctor.rb', line 55

def exit_code
  problems.size
end

#problemsObject



51
52
53
# File 'lib/aid/scripts/doctor.rb', line 51

def problems
  @checks.map(&:problems).flatten
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aid/scripts/doctor.rb', line 26

def run
  puts <<~HELP
    To implement this script for your repository, create the following
    file in #{colorize(:green, "#{aid_directory}/doctor.rb")}:

    class Doctor < Aid::Scripts::Doctor
      def run
        check_phantomjs_installed
      end

      private

      def check_phantomjs_installed
        check name: "PhantomJS installed",
          command: "which phantomjs",
          remedy: command("brew install phantomjs")
      end
    end

    You can add as many checks to your script as you want.
  HELP

  exit
end