require 'bundler/setup'

namespace :db do
  desc 'Run migrations'
  task :migrate, [:version] do |t, args|
    require 'sequel/core'
    # load configuration
    require_relative 'src/config'
    conf = Config.new()

    Sequel.extension :migration
    version = args[:version].to_i if args[:version]
    Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database')) do |db|
      Sequel::Migrator.run(db, 'db/migrations', target: version)
    end
  end
end

namespace :server do
  task :start do
    ENV['RACK_ENV'] = 'production'
    system("puma")
  end

  task :dev do
    system('rerun --no-notify --dir="src/" puma')
  end
end

namespace :test do
  task :unit do
    ENV['RACK_ENV'] = 'testing'
    system("rspec")
  end

  task :lint do
    system("rubocop src/ spec/")
  end
end
