# Maintainer: George Rawlinson <george@rawlinson.net.nz>

_gemname=oj
pkgname=ruby-$_gemname
pkgver=3.12.1
pkgrel=1
pkgdesc='The fastest JSON parser and object serializer'
arch=('x86_64')
url='https://github.com/ohler55/oj'
license=('MIT')
depends=('ruby')
options=(!emptydirs)
source=("https://rubygems.org/downloads/$_gemname-$pkgver.gem")
noextract=("$_gemname-$pkgver.gem")
b2sums=('415ffef51e0b5c3f6b10d9cede061b99838cf63b49b13b9d5c9de22fafb2537cb40d48277da60c78902c6c7151fc5151a44b291c02e766350f8163624a87c3f7')

package() {
  local _gemdir="$(ruby -e'puts Gem.default_dir')"

  gem install \
    --ignore-dependencies \
    --no-user-install \
    --no-document \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_gemname-$pkgver.gem"

  # delete cache
  cd "$pkgdir/$_gemdir"
  rm -rf cache

  cd "gems/$_gemname-$pkgver"
  # delete unnecessary folders
  rm -rf test ext
  # move documentation
  install -vd "$pkgdir/usr/share/doc/$pkgname"
  mv README.md pages "$pkgdir/usr/share/doc/$pkgname"
  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  mv LICENSE "$pkgdir/usr/share/licenses/$pkgname"
}