#!/usr/bin/env bash
set -eo pipefail

announce() {
  printf "\n--- $@\n"
}

announce "Installing Ruby"
mise install

announce "Installing dependencies"
gem install bundler --conservative
bundle check || bundle install

announce "Preparing database"
if [[ $* == *--reset* ]]; then
  rails db:reset
else
  rails db:prepare
fi

announce "Removing old logs and tempfiles"
rails log:clear tmp:clear

echo
echo "Start developing with bin/dev"
