(use-modules
  ((guix licenses) #:prefix license:)
  (guix packages)
  (guix download)
  (guix git-download)
  (guix build-system ruby)
  (guix build-system copy)
  (gnu packages rails)
  (gnu packages ruby)
  (gnu packages tls)
  (gnu packages databases)
  (ice-9 rdelim)
  (ice-9 popen))

(define-public ruby-eventmachine-openssl
  (package
    (inherit ruby-eventmachine)
    (inputs `(("openssl" ,openssl)))))

(define-public ruby-sucker-punch
  (package
    (name "ruby-sucker-punch")
    (version "2.0.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "sucker_punch" version))
        (sha256
          (base32
            "008vv7gpv2nm5n1njzvabd3aagbywc240y23vifvq6plir53ybay"))))
    (build-system ruby-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'extract-gemspec 'less-strict-dependencies
           (lambda _
             (substitute* "sucker_punch.gemspec"
               (("1.0.0") "1.0"))
             #t)))))
    (propagated-inputs
      `(("ruby-concurrent" ,ruby-concurrent)))
    (native-inputs
     `(("ruby-pry" ,ruby-pry)))
    (synopsis
      "Asynchronous processing library for Ruby")
    (description
      "Asynchronous processing library for Ruby")
    (home-page
      "https://github.com/brandonhilkert/sucker_punch")
    (license license:expat)))

(define-public ruby-countdownlatch
  (package
    (name "ruby-countdownlatch")
    (version "1.0.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "countdownlatch" version))
        (sha256
          (base32
            "1v6pbay6z07fp7yvnba1hmyacbicvmjndd8rn2h1b5rmpcb5s0j3"))))
    (build-system ruby-build-system)
    (synopsis
      "A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes")
    (description
      "This package provides a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes")
    (home-page
      "https://github.com/benlangfeld/countdownlatch")
    (license license:expat)))

(define-public ruby-blather
  (package
    (name "ruby-blather")
    (version "37fb26593aa776dd91965796e4d9ff79b05f334a")
    (source
      (origin
      (method git-fetch)
      ;; Download from GitHub because the rubygems version requires old
      ;; version of bundler Rakefile.
      (uri (git-reference
          (url "https://github.com/adhearsion/blather")
          (commit version)))
      (file-name (git-file-name name version))
        (sha256
          (base32
            "0k9viwpbd4ifmiv22x2vh2vvc5wgvcxg7x7bwn5nkc5aspisxlq2"))))
    (build-system ruby-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'extract-gemspec 'less-strict-dependencies
           (lambda _
             (substitute* "blather.gemspec"
               ((".*guard-rspec.*") "\n")
                ((".*bluecloth.*") "\n"))
             #t)))))
    (propagated-inputs
      `(("ruby-activesupport" ,ruby-activesupport)
        ("ruby-eventmachine" ,ruby-eventmachine)
        ("ruby-niceogiri" ,ruby-niceogiri)
        ("ruby-nokogiri" ,ruby-nokogiri)
        ("ruby-sucker-punch" ,ruby-sucker-punch)))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-yard" ,ruby-yard)
       ("ruby-countdownlatch" ,ruby-countdownlatch)
       ("ruby-rb-fsevent" ,ruby-rb-fsevent)
       ("ruby-mocha" ,ruby-mocha-1)))
    (synopsis
      "An XMPP DSL for Ruby written on top of EventMachine and Nokogiri")
    (description
      "An XMPP DSL for Ruby written on top of EventMachine and Nokogiri")
    (home-page "http://adhearsion.com/blather")
    (license license:expat)))

(define-public ruby-rspec-junit-formatter
  (package
    (name "ruby-rspec-junit-formatter")
    (version "0.6.0")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "rspec_junit_formatter" version))
              (sha256
               (base32
                "059bnq1gcwl9g93cqf13zpz38zk7jxaa43anzz06qkmfwrsfdpa0"))))
    (build-system ruby-build-system)
    (arguments
     `(#:tests? #f))
    (propagated-inputs (list ruby-rspec-core))
    (synopsis
     "RSpec results that your continuous integration service can read.")
    (description
     "RSpec results that your continuous integration service can read.")
    (home-page "https://github.com/sj26/rspec_junit_formatter")
    (license license:expat)))

(define-public ruby-braintree
  (package
    (name "ruby-braintree")
    (version "4.12.0")
    (source
     (origin
       (method git-fetch)
       ;; Download from GitHub because the rubygems version does not contain
       ;; Rakefile.
       (uri (git-reference
             (url "https://github.com/braintree/braintree_ruby")
             (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "0gfgkymy3655drwgs42bj9ap9qib1l30sajxmypmp6s75m9w3gsh"))))
    (build-system ruby-build-system)
    (arguments
     `(#:test-target "test:unit"
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'less-strict-dependencies
           (lambda _
             (substitute* "Gemfile"
               (("gem \"libxml-ruby\", \"3.2.0\"") "gem \"libxml-ruby\", \"~> 3.0.0\"")
               (("gem \"rubocop\".*") "")
               (("gem \"rake\", \"13.0.1\"") "gem \"rake\", \"~> 13.0.6\"")
               (("gem \"rspec\", \"3.9.0\"") "gem \"rspec\", \"~> 3.12.0\"")
               (("gem \"pry\", \"0.13.1\"") "gem \"pry\", \"~> 0.14.2\""))
             (substitute* "Rakefile"
               (("sh \"rubocop\"") "")))))))
    (propagated-inputs
      `(("ruby-builder" ,ruby-builder)
        ("ruby-rexml" ,ruby-rexml)))
    (native-inputs
	  (list
		ruby-rspec
		ruby-libxml
		ruby-pry
		ruby-rake
		ruby-webrick
		ruby-rspec-junit-formatter))
    (synopsis
      "Resources and tools for developers to integrate Braintree's global payments platform.")
    (description
      "Resources and tools for developers to integrate Braintree's global payments platform.")
    (home-page "https://www.braintreepayments.com/")
    (license license:expat)))

(define-public ruby-value-semantics
  (package
    (name "ruby-value-semantics")
    (version "3.6.1")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "value_semantics" version))
        (sha256
          (base32
            "1vdwai8wf6r1fkvdpyz1vzxm89q7ghjvb3pqpg2kvwibwzd99dnx"))))
    (build-system ruby-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _
             (invoke "rspec")
             #t)))))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)))
    (synopsis
      "
    Generates modules that provide conventional value semantics for a given set of attributes.
    The behaviour is similar to an immutable `Struct` class,
    plus extensible, lightweight validation and coercion.
  ")
    (description
      "
    Generates modules that provide conventional value semantics for a given set of attributes.
    The behaviour is similar to an immutable `Struct` class,
    plus extensible, lightweight validation and coercion.
  ")
    (home-page
      "https://github.com/tomdalling/value_semantics")
    (license license:expat)))

(define-public ruby-promise.rb
  (package
    (name "ruby-promise.rb")
    (version "0.7.4")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "promise.rb" version))
        (sha256
          (base32
            "0a819sikcqvhi8hck1y10d1nv2qkjvmmm553626fmrh51h2i089d"))))
    (build-system ruby-build-system)
    (arguments
     `(#:test-target "spec"
       #:phases
       (modify-phases %standard-phases
         (add-after 'extract-gemspec 'less-strict-dependencies
           (lambda _
             (substitute* "Rakefile"
               (("if Gem.ruby_version.*") "if false\n"))
             (substitute* "spec/spec_helper.rb"
               ((".*devtools/spec_helper.*") "\n"))
             #t)))))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-rspec-its" ,ruby-rspec-its)
       ("ruby-awesome-print" ,ruby-awesome-print)
       ("ruby-fuubar" ,ruby-fuubar)))
    (synopsis "Promises/A+ for Ruby")
    (description "Promises/A+ for Ruby")
    (home-page "https://github.com/lgierth/promise")
    (license license:unlicense)))

(define-public ruby-multicodecs
  (package
    (name "ruby-multicodecs")
    (version "0.2.1")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "multicodecs" version))
        (sha256
          (base32
            "0drq267di57l9zqw6zvqqimilz42rbc8z7392dwkk8wslq30s7v8"))))
    (build-system ruby-build-system)
    (synopsis
      "This gem provides a PORO of the multicodec table for use with other
    multiformat ruby gems.")
    (description
      "This gem provides a PORO of the multicodec table for use with other
    multiformat ruby gems.")
    (home-page
      "https://github.com/SleeplessByte/ruby-multicodec")
    (license license:expat)))

(define-public ruby-multihashes
  (package
    (name "ruby-multihashes")
    (version "0.2.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "multihashes" version))
        (sha256
          (base32
            "17wiyy3fiv8rpgdv9ca01yncsmaaf8yg15bg18wc7m9frss1vgqg"))))
    (build-system ruby-build-system)
    (propagated-inputs
      `(("ruby-multicodecs" ,ruby-multicodecs)))
    (synopsis
      "A simple, low-level multihash (https://github.com/jbenet/multihash) implementation for ruby.")
    (description
      "This package provides a simple, low-level multihash (https://github.com/jbenet/multihash) implementation for ruby.")
    (home-page
      "https://github.com/neocities/ruby-multihashes")
    (license license:expat)))

(define-public ruby-lazy-object
  (package
    (name "ruby-lazy-object")
    (version "0.0.3")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "lazy_object" version))
        (sha256
          (base32
            "08px15lahc28ik9smvw1hgamf792gd6gq0s4k94yq1h7jq25wjn8"))))
    (build-system ruby-build-system)
    (arguments
     '(#:test-target "spec"))
    (synopsis
      "It's an object wrapper that forwards all calls to the reference object. This object is not created until the first method dispatch.")
    (description
      "It's an object wrapper that forwards all calls to the reference object.  This object is not created until the first method dispatch.")
    (home-page "")
    (license license:expat)))

(define-public ruby-citrus
  (package
    (name "ruby-citrus")
    (version "3.0.2")
    (source
     (origin
       (method git-fetch)
       ;; Download from GitHub because the rubygems version does not contain
       ;; files needed for tests
       (uri (git-reference
             (url "https://github.com/mjackson/citrus")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "197wrgqrddgm1xs3yvjvd8vkvil4h4mdrcp16jmd4b57rxrrr769"))))
    (build-system ruby-build-system)
    (synopsis "Parsing Expressions for Ruby")
    (description "Parsing Expressions for Ruby")
    (home-page "http://mjackson.github.io/citrus")
    (license license:expat)))

(define-public ruby-cbor
  (package
    (name "ruby-cbor")
    (version "0.5.9.6")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "cbor" version))
        (sha256
          (base32
            "0511idr8xps9625nh3kxr68sdy6l3xy2kcz7r57g47fxb1v18jj3"))))
    (build-system ruby-build-system)
    (arguments
     '(#:test-target "spec"))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-rake-compiler" ,ruby-rake-compiler)
       ("ruby-yard" ,ruby-yard)))
    (synopsis
      "CBOR is a library for the CBOR binary object representation format, based on Sadayuki Furuhashi's MessagePack library.")
    (description
      "CBOR is a library for the CBOR binary object representation format, based on Sadayuki Furuhashi's MessagePack library.")
    (home-page "http://cbor.io/")
    (license license:asl2.0)))

(define-public ruby-gem-release
  (package
    (name "ruby-gem-release")
    (version "2.2.2")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "gem-release" version))
        (sha256
          (base32
            "108rrfaiayi14zrqbb6z0cbwcxh8n15am5ry2a86v7c8c3niysq9"))))
    (build-system ruby-build-system)
    (arguments
     ;; No rakefile
     `(#:tests? #f))
    (synopsis
      "Release your ruby gems with ease. (What a bold statement for such a tiny plugin ...)")
    (description
      "Release your ruby gems with ease. (What a bold statement for such a tiny plugin ...)")
    (home-page
    "https://github.com/svenfuchs/gem-release")
    (license license:expat)))

(define-public ruby-base32
  (package
    (name "ruby-base32")
    (version "0.3.4")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "base32" version))
        (sha256
          (base32
            "1fjs0l3c5g9qxwp43kcnhc45slx29yjb6m6jxbb2x1krgjmi166b"))))
    (build-system ruby-build-system)
    (native-inputs
     `(("ruby-gem-release" ,ruby-gem-release)))
    (synopsis
      "Ruby extension for base32 encoding and decoding")
    (description
      "Ruby extension for base32 encoding and decoding")
    (home-page "https://github.com/stesla/base32")
    (license license:expat)))

(define-public ruby-dhall
  (package
    (name "ruby-dhall")
    (version "0.5.3.fixed")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "dhall" version))
        (sha256
          (base32
            "1qn7fpiakzpllks43m7r3wh6a2rypxgg02y09zzk27lhqv6bbbrz"))))
    (build-system ruby-build-system)
    (arguments
     ;; No test in gem archive
     `(#:tests? #f))
    (propagated-inputs
      `(("ruby-base32" ,ruby-base32)
        ("ruby-cbor" ,ruby-cbor)
        ("ruby-citrus" ,ruby-citrus)
        ("ruby-lazy-object" ,ruby-lazy-object)
        ("ruby-multihashes" ,ruby-multihashes)
        ("ruby-promise.rb" ,ruby-promise.rb)
        ("ruby-value-semantics" ,ruby-value-semantics)))
    (synopsis
      "This is a Ruby implementation of the Dhall configuration language. Dhall is a powerful, but safe and non-Turing-complete configuration language. For more information, see: https://dhall-lang.org")
    (description
      "This is a Ruby implementation of the Dhall configuration language.  Dhall is a powerful, but safe and non-Turing-complete configuration language.  For more information, see: https://dhall-lang.org")
    (home-page
      "https://git.sr.ht/~singpolyma/dhall-ruby")
    (license license:gpl3)))

(define-public ruby-money
  (package
    (name "ruby-money")
    (version "6.16.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "money" version))
        (sha256
          (base32
            "0jkmsj5ymadik7bvl670bqwmvhsdyv7hjr8gq9z293hq35gnyiyg"))))
    (build-system ruby-build-system)
    (arguments
     ;; No rakefile
     `(#:tests? #f))
    (propagated-inputs `(("ruby-i18n" ,ruby-i18n)))
    (synopsis
      "A Ruby Library for dealing with money and currency conversion.")
    (description
      "This package provides a Ruby Library for dealing with money and currency conversion.")
    (home-page "https://rubymoney.github.io/money")
    (license license:expat)))

(define-public ruby-monetize
  (package
    (name "ruby-monetize")
    (version "1.11.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "monetize" version))
        (sha256
          (base32
            "0cna2myxdbwfq0gn6k2hgrh368dq7wld3jklm96443ysykd0difn"))))
    (build-system ruby-build-system)
    (arguments
     '(#:test-target "spec"))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)))
    (propagated-inputs `(("ruby-money" ,ruby-money)))
    (synopsis
      "A library for converting various objects into `Money` objects.")
    (description
      "This package provides a library for converting various objects into `Money` objects.")
    (home-page
      "https://github.com/RubyMoney/monetize")
    (license license:expat)))

(define-public ruby-money-open-exchange-rates
  (package
    (name "ruby-money-open-exchange-rates")
    (version "1.4.0")
    (source
     (origin
       (method git-fetch)
       ;; Download from GitHub because the rubygems version does not contain
       ;; Rakefile.
       (uri (git-reference
             (url "https://github.com/spk/money-open-exchange-rates")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "11xwqli8snr19k48yh8h77sal5vxd4snzq9gxg08v61f0574m3gw"))))
    (build-system ruby-build-system)
    (propagated-inputs `(("ruby-money" ,ruby-money)))
    (native-inputs
     `(("ruby-minitest" ,ruby-minitest)
       ("ruby-mocha" ,ruby-mocha-1)
       ("ruby-timecop" ,ruby-timecop)
       ("ruby-webmock" ,ruby-webmock)
       ("ruby-monetize" ,ruby-monetize)
       ("ruby-rake" ,ruby-rake)
       ("ruby-rubocop" ,ruby-rubocop)))
    (synopsis
      "A gem that calculates the exchange rate using published rates from open-exchange-rates. Compatible with the money gem.")
    (description
      "This package provides a gem that calculates the exchange rate using published rates from open-exchange-rates.  Compatible with the money gem.")
    (home-page
      "http://github.com/spk/money-open-exchange-rates")
    (license license:expat)))

(define-public ruby-roda
  (package
    (name "ruby-roda")
    (version "3.47.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "roda" version))
        (sha256
          (base32
            "1g3zs4bk8hqii15ci1hsykcsya88vr2qv63gp1qbcx4bm14l8lkl"))))
    (build-system ruby-build-system)
    (arguments
     ;; No rakefile
     `(#:tests? #f))
    (propagated-inputs `(("ruby-rack" ,ruby-rack)))
    (synopsis "Routing tree web toolkit")
    (description "Routing tree web toolkit")
    (home-page "http://roda.jeremyevans.net")
    (license license:expat)))

(define-public ruby-nori
  (package
    (name "ruby-nori")
    (version "2.6.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "nori" version))
        (sha256
          (base32
            "066wc774a2zp4vrq3k7k8p0fhv30ymqmxma1jj7yg5735zls8agn"))))
    (build-system ruby-build-system)
    (arguments
     ;; Tests require too old version of rspec
     `(#:tests? #f))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-rake" ,ruby-rake)
       ("ruby-nokogiri" ,ruby-nokogiri)))
    (synopsis "XML to Hash translator")
    (description "XML to Hash translator")
    (home-page "https://github.com/savonrb/nori")
    (license license:expat)))

(define-public ruby-faraday-middleware
  (package
    (name "ruby-faraday-middleware")
    (version "1.1.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "faraday_middleware" version))
        (sha256
          (base32
            "0kgcphf7n74l3wlcvxafcp6a4l18b1bf4qslvz5dqj6v3gc8h8j4"))))
    (build-system ruby-build-system)
    (arguments
     ;; No rakefile
     `(#:tests? #f))
    (propagated-inputs
      `(("ruby-faraday" ,ruby-faraday)))
    (synopsis "Various middleware for Faraday")
    (description "Various middleware for Faraday")
    (home-page
      "https://github.com/lostisland/faraday_middleware")
    (license license:expat)))

(define-public ruby-bandwidth-iris
  (package
    (name "ruby-bandwidth-iris")
    (version "list-port-ins")
    (source
      (origin
      (method git-fetch)
      (uri (git-reference
          (url "https://github.com/singpolyma/ruby-bandwidth-iris")
          (commit version)))
        (sha256
          (base32
            "0vab3fbkps6kvkph38ssfk7s9j646l4gz8p1q4glvi26js0v9rhc"))))
    (build-system ruby-build-system)
    (arguments
     ; Tests don't require helper for some reason, so all fail...
     '(#:tests? #f))
    (propagated-inputs
      `(("ruby-activesupport" ,ruby-activesupport)
        ("ruby-builder" ,ruby-builder)
        ("ruby-faraday" ,ruby-faraday)
        ("ruby-faraday-middleware"
         ,ruby-faraday-middleware)
        ("ruby-nori" ,ruby-nori)))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-yard" ,ruby-yard)))
    (synopsis
      "Gem for integrating to Bandwidth's Iris API")
    (description
      "Gem for integrating to Bandwidth's Iris API")
    (home-page
      "https://github.com/bandwidthcom/ruby-bandwidth-iris")
    (license license:expat)))

(define-public ruby-sentry-core
  (package
    (name "ruby-sentry-core")
    (version "4.3.1")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "sentry-ruby-core" version))
        (sha256
          (base32
            "13z35s9mflh3v775a0scsnqhscz9q46kaak38y7zmx32z7sg2a3a"))))
    (build-system ruby-build-system)
    (arguments
     ; No rakefile in gem
     '(#:tests? #f))
    (propagated-inputs
      `(("ruby-concurrent" ,ruby-concurrent)
        ("ruby-faraday" ,ruby-faraday)))
    (synopsis
      "A gem that provides a client interface for the Sentry error logger")
    (description
      "This package provides a gem that provides a client interface for the Sentry error logger")
    (home-page
      "https://github.com/getsentry/sentry-ruby")
    (license license:expat)))

(define-public ruby-sentry
  (package
    (name "ruby-sentry")
    (version "4.3.1")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "sentry-ruby" version))
        (sha256
          (base32
            "101q3141xfkmh7vi8h4sjqqmxcx90xhyq51lmfnhfiwgii7cn9k8"))))
    (build-system ruby-build-system)
    (arguments
     ; No rakefile in gem
     '(#:tests? #f))
    (propagated-inputs
      `(("ruby-concurrent" ,ruby-concurrent)
        ("ruby-faraday" ,ruby-faraday)
        ("ruby-sentry-core" ,ruby-sentry-core)))
    (synopsis
      "A gem that provides a client interface for the Sentry error logger")
    (description
      "This package provides a gem that provides a client interface for the Sentry error logger")
    (home-page
      "https://github.com/getsentry/sentry-ruby")
    (license license:expat)))

(define-public ruby-webrick
  (package
    (name "ruby-webrick")
    (version "1.7.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "webrick" version))
        (sha256
          (base32
            "1d4cvgmxhfczxiq5fr534lmizkhigd15bsx5719r5ds7k7ivisc7"))))
    (build-system ruby-build-system)
    (synopsis
      "WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.")
    (description
      "WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.")
    (home-page "https://github.com/ruby/webrick")
    (license #f)))

(define-public ruby-interception
  (package
    (name "ruby-interception")
    (version "0.5")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "interception" version))
        (sha256
          (base32
            "01vrkn28psdx1ysh5js3hn17nfp1nvvv46wc1pwqsakm6vb1hf55"))))
    (build-system ruby-build-system)
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)))
    (synopsis
      "Provides a cross-platform ability to intercept all exceptions as they are raised.")
    (description
      "This package provides a cross-platform ability to intercept all exceptions as they are raised.")
    (home-page
      "http://github.com/ConradIrwin/interception")
    (license license:expat)))

(define-public ruby-pry-rescue
  (package
    (name "ruby-pry-rescue")
    (version "1.5.2")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "pry-rescue" version))
        (sha256
          (base32
            "1wn72y8y3d3g0ng350ld92nyjln012432q2z2iy9lhwzjc4dwi65"))))
    (build-system ruby-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'nuke-bad-test
           (lambda _
             (substitute* "spec/source_location_spec.rb"
               (("time = Time.now") "skip"))
             #t)))))
    (propagated-inputs
      `(("ruby-interception" ,ruby-interception)
        ("ruby-pry" ,ruby-pry)))
    (native-inputs
     `(("ruby-rspec" ,ruby-rspec)
       ("ruby-pry-stack-explorer" ,ruby-pry-stack-explorer)))
    (synopsis
      "Allows you to wrap code in Pry::rescue{ } to open a pry session at any unhandled exceptions")
    (description
      "Allows you to wrap code in Pry::rescue{ } to open a pry session at any unhandled exceptions")
    (home-page
      "https://github.com/ConradIrwin/pry-rescue")
    (license license:expat)))

(define-public ruby-rantly
  (package
    (name "ruby-rantly")
    (version "2.0.0")
    (source
      (origin
        (method url-fetch)
        (uri (rubygems-uri "rantly" version))
        (sha256
          (base32
            "11407cg0dzz83jsschnrpi9cqwz8b04q6bj6qj3m70ay52y222ix"))))
    (build-system ruby-build-system)
    (native-inputs
     `(("ruby-rubocop" ,ruby-rubocop)
       ("ruby-simplecov" ,ruby-simplecov)))
    (synopsis
      "Ruby Imperative Random Data Generator and Quickcheck")
    (description
      "Ruby Imperative Random Data Generator and Quickcheck")
    (home-page "https://github.com/rantly-rb/rantly")
    (license license:expat)))

(define-public ruby-em-promise.rb
  (package
    (name "ruby-em-promise.rb")
    (version "0.0.5")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "em_promise.rb" version))
              (sha256
               (base32
                "00rkmacyf6i2gq0giaxzwr24ygrwwzndrq7kkbpqcq9glk01w692"))))
    (build-system ruby-build-system)
   (arguments
    ;; No rakefile
    `(#:tests? #f))
    (propagated-inputs (list ruby-eventmachine ruby-promise.rb))
    (synopsis "A subclass of promise.rb Promise for EventMachine.")
    (description
     "This package provides a subclass of promise.rb Promise for EventMachine.")
    (home-page "https://git.singpolyma.net/em_promise.rb")
    (license #f)))

(define-public ruby-em-socksify
  (package
    (name "ruby-em-socksify")
    (version "0.3.2")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "em-socksify" version))
              (sha256
               (base32
                "0rk43ywaanfrd8180d98287xv2pxyl7llj291cwy87g1s735d5nk"))))
    (build-system ruby-build-system)
   (arguments
    ;; Tests are broken
    `(#:tests? #f))
    (propagated-inputs (list ruby-eventmachine))
    (synopsis "Transparent proxy support for any EventMachine protocol")
    (description "Transparent proxy support for any EventMachine protocol")
    (home-page "https://github.com/igrigorik/em-socksify")
    (license license:expat)))

(define-public ruby-rspec-collection-matchers
  (package
    (name "ruby-rspec-collection-matchers")
    (version "1.2.0")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "rspec-collection_matchers" version))
              (sha256
               (base32
                "1864xlxl7mi6mvjyp85a0gc10cyvpf6bj8lc86sf8737wlzn12ks"))))
    (build-system ruby-build-system)
   (arguments
    ;; No rakefile
    `(#:tests? #f))
    (propagated-inputs (list ruby-rspec-expectations))
    (synopsis
     "Collection cardinality matchers, extracted from rspec-expectations")
    (description
     "Collection cardinality matchers, extracted from rspec-expectations")
    (home-page "https://github.com/rspec/rspec-collection_matchers")
    (license license:expat)))

(define-public ruby-cookiejar
  (package
    (name "ruby-cookiejar")
    (version "0.3.3")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "cookiejar" version))
              (sha256
               (base32
                "0q0kmbks9l3hl0wdq744hzy97ssq9dvlzywyqv9k9y1p3qc9va2a"))))
    (build-system ruby-build-system)
   (native-inputs
    `(("ruby-rspec" ,ruby-rspec)
     ("ruby-rspec-collection-matchers" ,ruby-rspec-collection-matchers)
     ("ruby-yard" ,ruby-yard)))
    (synopsis
     "Allows for parsing and returning cookies in Ruby HTTP client code")
    (description
     "Allows for parsing and returning cookies in Ruby HTTP client code")
    (home-page "http://alkaline-solutions.com")
    (license #f)))

(define-public ruby-em-http-request
  (package
    (name "ruby-em-http-request")
    (version "1.1.7")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "em-http-request" version))
              (sha256
               (base32
                "1azx5rgm1zvx7391sfwcxzyccs46x495vb34ql2ch83f58mwgyqn"))))
    (build-system ruby-build-system)
    (arguments
     ;; Tests need a whole other set of dependencies
     `(#:tests? #f))
    (propagated-inputs (list ruby-addressable ruby-cookiejar ruby-em-socksify
                             ruby-eventmachine ruby-http-parser.rb))
    (synopsis "EventMachine based, async HTTP Request client")
    (description "EventMachine based, async HTTP Request client")
    (home-page "http://github.com/igrigorik/em-http-request")
    (license license:expat)))

(define-public ruby-em-synchrony
  (package
    (name "ruby-em-synchrony")
    (version "1.0.6")
    (source (origin
              (method url-fetch)
              (uri (rubygems-uri "em-synchrony" version))
              (sha256
               (base32
                "1jh6ygbcvapmarqiap79i6yl05bicldr2lnmc46w1fyrhjk70x3f"))))
    (build-system ruby-build-system)
    (arguments
     ;; Tests need a whole other set of dependencies
     `(#:tests? #f))
    (propagated-inputs (list ruby-eventmachine))
    (synopsis "Fiber aware EventMachine libraries")
    (description "Fiber aware EventMachine libraries")
    (home-page "http://github.com/igrigorik/em-synchrony")
    (license license:expat)))

;;;;

(define %source-dir (dirname (current-filename)))
(define %git-dir (string-append %source-dir "/.git"))

; Bake a template by eval'ing the leaves
(define-public (bake tmpl)
 (list
  (car tmpl)
  (cons (caadr tmpl) (map
   (lambda (x) (list (car x) (eval (cadr x) (current-module))))
   (cdadr tmpl)))))

; double-escaped template of the jmp-pay sexp
; This allows us to bake the expression without doing a full eval to a record,
; so it can be written
(define-public jmp-pay-template
  '((package-input-rewriting `((,ruby-eventmachine . ,ruby-eventmachine-openssl)))
  (package
    (name "jmp-pay")
    (version (read-line (open-pipe* OPEN_READ "git" "--git-dir" %git-dir "describe" "--always" "--dirty")))
    (source
     `(origin
       (method git-fetch)
       (uri (git-reference
             (recursive? #t)
             (url "https://git.singpolyma.net/jmp-pay")
             (commit ,(read-line (open-pipe* OPEN_READ "git" "--git-dir" %git-dir "rev-parse" "HEAD")))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         ,(read-line (open-pipe* OPEN_READ "guix" "hash" "-rx" %source-dir))))))
    (build-system 'copy-build-system)
    (arguments
     ''(#:install-plan '(("." "share/jmp-pay"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'wrap
           (lambda* (#:key outputs #:allow-other-keys)
             (use-modules (ice-9 ftw))
             (let* ((out (assoc-ref outputs "out"))
                    (appbindir (string-append out "/share/jmp-pay/bin/"))
                    (bindir (string-append out "/bin/")))
               (for-each (lambda (bin)
                 (mkdir-p bindir)
                 (let ((binstub (string-append bindir bin)))
                   (call-with-output-file binstub
                     (lambda (port)
                       (format port
                         "#!~a~%ENV['GEM_PATH'] = ['~a', ENV['GEM_PATH']].compact.join(':')~%Gem.clear_paths~%load '~a~a'~%"
                         (which "ruby")
                         (getenv "GEM_PATH")
                         appbindir
                         bin)))
                   (chmod binstub #o755)))
                 (scandir appbindir
                   (lambda (f) (eq? 'regular (stat:type (stat (string-append appbindir f))))))))
             #t))
         (add-before 'install 'check
           (lambda _
             (invoke "rake" "test")
             #t)))))
    (propagated-inputs
      '`(("ruby-blather" ,ruby-blather)
        ("ruby-braintree" ,ruby-braintree)
        ("ruby-dhall" ,ruby-dhall)
        ("ruby-money-open-exchange-rates" ,ruby-money-open-exchange-rates)
        ("ruby-pg" ,ruby-pg)
        ("ruby-redis" ,ruby-redis)
        ("ruby-roda" ,ruby-roda)
        ("ruby-em-promise.rb" ,ruby-em-promise.rb)
        ("ruby-em-synchrony" ,ruby-em-synchrony)
        ("ruby-em-http-request" ,ruby-em-http-request)
        ("ruby-bandwidth-iris" ,ruby-bandwidth-iris)
        ("ruby-mail" ,ruby-mail)
        ("ruby-sentry" ,ruby-sentry)
        ("ruby" ,ruby) ;; Normally ruby-build-system adds this for us
        ("ruby-slim" ,ruby-slim)))
    (native-inputs
     '`(("ruby-rantly" ,ruby-rantly)
       ("ruby-rake" ,ruby-rake)
       ("ruby-webmock" ,ruby-webmock)))
    (synopsis
      "Payment infrastructure for JMP.chat")
    (description
      "Web service and cronjobs for payment handling")
    (home-page
      "https://git.singpolyma.net/jmp-pay")
    (license 'license:agpl3))))

; Baked version of jmp-pay-template with leaves eval'd
(define-public jmp-pay-baked
	(bake jmp-pay-template))

; Build clean from git the version from a local clone
; To build whatever is sitting in local use:
; guix build --with-source=$PWD -f guix.scm

(eval jmp-pay-baked (current-module))
