# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: farawayer <farwayer@gmail.com>
# Contributor: Tim Meusel <tim@bastelfreak.de>

_gemname='public_suffix'
pkgname="ruby-${_gemname}"
pkgver=5.0.3
pkgrel=1
pkgdesc='Domain name parser based on the Public Suffix List'
arch=('any')
url='https://simonecarletti.com/code/publicsuffix-ruby'
license=('MIT')
makedepends=('ruby-rake' 'ruby-bundler' 'ruby-yard' 'ruby-rdoc')
checkdepends=('ruby-minitest' 'ruby-mocha')
depends=('ruby')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/weppos/publicsuffix-ruby/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz")
options=("!emptydirs")
sha512sums=('ae6b1db7166366d96411902e5b1fae44538085849ec61221f763c487b8069823032cf3d57930d5d56ba75d114df0a66b981663add9e9d45b43508d2a42996d75')

prepare() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"

  sed --in-place 's|git ls-files|find|' "${_gemname}.gemspec"
  sed --in-place '/test_files/d' "${_gemname}.gemspec"
  sed --in-place '/rubocop/Id' Rakefile
  sed --in-place '/reporters/Id' test/test_helper.rb
}

build() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  rake test
}

package() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --ignore-dependencies --no-user-install -i "${pkgdir}${_gemdir}" \
    -n "${pkgdir}/usr/bin" ${_gemname}-${pkgver}.gem

  install -Dm 644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}/"
  install -Dm 644 README.md SECURITY.md CHANGELOG.md 2.0-Upgrade.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}

# vim: ts=2 sw=2 et:
