class AbtionScripts::Doctor

Public Class Methods

description() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 35
def self.description
  "Checks the health of your development environment"
end
help() click to toggle source
# File lib/abtion_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/abtion_scripts/doctor.rb, line 57
def self.help_subcommands
  {
    "abtion doctor" => "runs health checks and gives a report",
    "abtion 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 AbtionScripts::Base::new
# File lib/abtion_scripts/doctor.rb, line 39
def initialize(*args)
  super
  @checks = []
end

Public Instance Methods

check(**options) click to toggle source
# File lib/abtion_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/abtion_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/abtion_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/abtion_scripts/doctor.rb, line 64
def run_doctor
  run_checks
  report
end

Private Instance Methods

check_db_exists() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 142
def check_db_exists
  check \
    name: "Development database exists",
    command: "source .envrc && rails runner -e development 'ActiveRecord::Base.connection'",
    remedy: command("rake db:setup")

  check \
    name: "Test database exists",
    command: "source .envrc && rails runner -e test 'ActiveRecord::Base.connection'",
    remedy: command("rake db:setup")
end
check_db_migrated() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 154
def check_db_migrated
  check \
    name: "DB is migrated",
    command: "source .envrc && rails runner 'ActiveRecord::Migration.check_pending!'",
    remedy: command("rake db:migrate db:test:prepare")
end
check_direnv_installed() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 161
def check_direnv_installed
  check \
    name: "direnv installed",
    command: "which direnv",
    remedy: command("brew install direnv")
end
check_env_file_exists() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 182
def check_env_file_exists
  check \
    name: ".env file exists (for 'heroku local')",
    command: "stat .env",
    remedy: command("ln -s .envrc .env")
end
check_envrc_file_exists() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 175
def check_envrc_file_exists
  check \
    name: ".envrc file exists",
    command: "stat .envrc",
    remedy: command("cp .envrc.sample .envrc")
end
check_gemfile_dependencies() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 135
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/abtion_scripts/doctor.rb, line 168
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/abtion_scripts/doctor.rb, line 114
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/abtion_scripts/doctor.rb, line 128
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/abtion_scripts/doctor.rb, line 121
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/abtion_scripts/doctor.rb, line 197
def command(s)
  "run #{colorize :command, s}"
end
default_checks() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 99
def default_checks
  %i[
    check_envrc_file_exists
    check_env_file_exists
    check_direnv_installed
    check_gemfile_dependencies
    check_postgres_launchctl
    check_postgres_running
    check_postgres_role
    check_db_exists
    check_db_migrated
    check_phantomjs_installed
  ]
end
problems() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 189
def problems
  @checks.map(&:problems).flatten
end
report() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 193
def report
  exit problems.size
end
run_checks() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 89
def run_checks
  run_default_checks
end
run_default_checks() click to toggle source
# File lib/abtion_scripts/doctor.rb, line 93
def run_default_checks
  default_checks.each do |check|
    send(check)
  end
end