# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-async-http
pkgver=0.92.1
pkgrel=1
pkgdesc='A HTTP client and server library'
arch=(any)
url='https://github.com/socketry/async-http'
license=(MIT)
depends=(
  ruby
  ruby-async
  ruby-async-pool
  ruby-io-endpoint
  ruby-io-stream
  ruby-metrics
  ruby-protocol-http
  ruby-protocol-http1
  ruby-protocol-http2
  ruby-protocol-url
  ruby-traces
)
makedepends=(
  ruby-rdoc
)
checkdepends=(
  ruby-async-container
  ruby-bake
  ruby-bake-test
  ruby-bake-test-external
  ruby-bundler
  ruby-covered
  ruby-decode
  ruby-localhost
  ruby-rack-test
  ruby-sus
  ruby-sus-fixtures-async
  ruby-sus-fixtures-async-http
  ruby-sus-fixtures-benchmark
  ruby-sus-fixtures-openssl
)
options=(!emptydirs)
source=(https://github.com/socketry/async-http/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha512sums=('e9f69afe6032c56f61c8f31984ccb0eda0a011e0b7d91ecbf2756127afb7e9ca07826a58ed7104082b5c515ffb5f7fbfd4c20a523ca3b6cd16be7ef6ab32da79')
b2sums=('636de1ff22980864fee461c7d417b0279462c209538cae0842fd410f4482f1b1e46f2f7321f0f7c8dfd7a329b02740d8bda252caff91539e094592f0c82308b7')

prepare() {
  cd async-http-$pkgver

  sed -r \
    -e 's|~>|>=|g' \
    -e '/signing_key/d' \
    -i async-http.gemspec

  sed --in-place \
    --expression '/group :maintenance/,/end/d' \
    --expression '/rubocop/d' \
    gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd async-http-$pkgver
  gem build async-http.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    async-http-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd async-http-$pkgver
  GEM_HOME="tmp_install/$_gemdir" bake test
  GEM_HOME="tmp_install/$_gemdir" sus
}

package() {
  cd async-http-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
