summaryrefslogtreecommitdiff
path: root/guix/import/gem.scm
diff options
context:
space:
mode:
authorTaiju HIGASHI <higashi@taiju.info>2022-09-09 22:47:36 +0900
committerChristopher Baines <mail@cbaines.net>2022-09-17 19:09:27 +0200
commit5d22261db3d5099d745b9e8c8484545e546b319e (patch)
tree2c72e5bd6d22e8a8d58ed60dca844ce6ef5ab496 /guix/import/gem.scm
parentc54ef97c80f98fba77304efc560945fe78a4bafb (diff)
import: gem: Support importing a specific version of a gem.
* guix/import/gem.scm: (rubygems-fetch, gem->guix-package) (gem-recursive-import): Fix to fetch the specified version of the gem. * guix/scripts/import/gem.scm (show-help): Update the help message. (guix-import-gem): Modify so the version number to be passed to subsequent procedures. * tests/gem.scm: Add tests. * doc/guix.texi (Invoking guix import): Document. Signed-off-by: Christopher Baines <mail@cbaines.net>
Diffstat (limited to 'guix/import/gem.scm')
-rw-r--r--guix/import/gem.scm19
1 files changed, 13 insertions, 6 deletions
diff --git a/guix/import/gem.scm b/guix/import/gem.scm
index 0e5bb7e635..ad1343bff4 100644
--- a/guix/import/gem.scm
+++ b/guix/import/gem.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -81,10 +82,12 @@
(requirements gem-dependency-requirements)) ;string
-(define (rubygems-fetch name)
- "Return a <gem> record for the package NAME, or #f on failure."
+(define* (rubygems-fetch name #:optional version)
+ "Return a <gem> record for the package NAME and VERSION, or #f on failure. If VERSION is #f or missing, return the latest version gem."
(and=> (json-fetch
- (string-append "https://rubygems.org/api/v1/gems/" name ".json"))
+ (if version
+ (string-append "https://rubygems.org/api/v2/rubygems/" name "/versions/" version ".json")
+ (string-append "https://rubygems.org/api/v1/gems/" name ".json")))
json->gem))
(define (ruby-package-name name)
@@ -122,8 +125,11 @@ VERSION, HASH, HOME-PAGE, DESCRIPTION, DEPENDENCIES, and LICENSES."
(define* (gem->guix-package package-name #:key (repo 'rubygems) version)
"Fetch the metadata for PACKAGE-NAME from rubygems.org, and return the
-`package' s-expression corresponding to that package, or #f on failure."
- (let ((gem (rubygems-fetch package-name)))
+`package' s-expression corresponding to that package, or #f on failure.
+Optionally include a VERSION string to fetch a specific version gem."
+ (let ((gem (if version
+ (rubygems-fetch package-name version)
+ (rubygems-fetch package-name))))
(if gem
(let* ((dependencies-names (map gem-dependency-name
(gem-dependencies-runtime
@@ -189,4 +195,5 @@ package on RubyGems."
(recursive-import package-name
#:repo '()
#:repo->guix-package gem->guix-package
- #:guix-name ruby-package-name))
+ #:guix-name ruby-package-name
+ #:version version))