class CitizenCodeScripts::Doctor

Public Class Methods

description() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 35
def self.description
  "Checks the health of your development environment"
end
help() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 53
def self.help
  "doctor - helps you diagnose any setup issues with this application\n"
end
help_subcommands() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 57
def self.help_subcommands
  {
    "citizen doctor" => "runs health checks and gives a report",
    "citizen doctor list" => "prints a list of default checks you can use when overriding doctor checks in your app"
  }
end
new(*args) click to toggle source
Calls superclass method CitizenCodeScripts::Base::new
# File lib/citizen_code_scripts/doctor.rb, line 39
def initialize(*args)
  super
  @checks = []
end

Public Instance Methods

check(**options) click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 80
def check(**options)
  check = Check.new(options)
  @checks << check

  check.run!
end
list_default_checks() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 69
def list_default_checks
  puts "These default checks are available for use in your overrides:"
  puts

  default_checks.each do |name|
    puts "  - #{colorize(:light_blue, name)}"
  end

  puts
end
run() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 44
def run
  case argv.first
  when "list"
    list_default_checks
  else
    run_doctor
  end
end
run_doctor() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 64
def run_doctor
  run_checks
  report
end

Private Instance Methods

check_db_migrated() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 140
def check_db_migrated
  check \
    name: "DB is migrated",
    command: "source .envrc && rails runner 'ActiveRecord::Migration.check_pending!'",
    remedy: command("rake db:migrate")
end
check_direnv_installed() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 147
def check_direnv_installed
  check \
    name: "direnv installed",
    command: "which direnv",
    remedy: command("brew install direnv")
end
check_envrc_file_exists() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 161
def check_envrc_file_exists
  check \
    name: "envrc",
    command: "stat .envrc",
    remedy: "get your .envrc file from 1password"
end
check_gemfile_dependencies() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 133
def check_gemfile_dependencies
  check \
    name: "Gemfile dependencies are up to date",
    command: "bundle check",
    remedy: command("bundle")
end
check_phantomjs_installed() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 154
def check_phantomjs_installed
  check \
    name: "PhantomJS installed",
    command: "which phantomjs",
    remedy: command("brew install phantomjs")
end
check_postgres_launchctl() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 112
def check_postgres_launchctl
  check \
    name: "postgres launchctl script is linked",
    command: "ls -1 ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist",
    remedy: command("ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents")
end
check_postgres_role() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 126
def check_postgres_role
  check \
    name: "postgres role exists",
    command: "psql -U postgres -l",
    remedy: command("createuser --superuser postgres")
end
check_postgres_running() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 119
def check_postgres_running
  check \
    name: "postgres is running",
    command: "psql -l",
    remedy: command("launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist")
end
command(s) click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 176
def command(s)
  "run #{colorize :command, s}"
end
default_checks() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 99
def default_checks
  %i[
    check_postgres_launchctl
    check_postgres_running
    check_postgres_role
    check_db_migrated
    check_direnv_installed
    check_phantomjs_installed
    check_gemfile_dependencies
    check_envrc_file_exists
  ]
end
problems() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 168
def problems
  @checks.map(&:problems).flatten
end
report() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 172
def report
  exit problems.size
end
run_checks() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 89
def run_checks
  run_default_checks
end
run_default_checks() click to toggle source
# File lib/citizen_code_scripts/doctor.rb, line 93
def run_default_checks
  default_checks.each do |check|
    send(check)
  end
end