aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/installer/managers/gem.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-03-12 08:21:15 +0100
committerGitHub <noreply@github.com>2023-03-12 08:21:15 +0100
commita01d02ad7f680aec98a1e2ec35b04cedd307cfa8 (patch)
tree1a09e274a1f2a4da85b911abcbb182a211035501 /lua/mason-core/installer/managers/gem.lua
parentfeat(golangci-lint): support linux_arm64 (#1089) (diff)
downloadmason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar.gz
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar.bz2
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar.lz
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar.xz
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.tar.zst
mason-a01d02ad7f680aec98a1e2ec35b04cedd307cfa8.zip
feat: add github registry source capabilities (#1091)
Diffstat (limited to 'lua/mason-core/installer/managers/gem.lua')
-rw-r--r--lua/mason-core/installer/managers/gem.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/lua/mason-core/installer/managers/gem.lua b/lua/mason-core/installer/managers/gem.lua
new file mode 100644
index 00000000..0eac275e
--- /dev/null
+++ b/lua/mason-core/installer/managers/gem.lua
@@ -0,0 +1,65 @@
+local installer = require "mason-core.installer"
+local log = require "mason-core.log"
+local platform = require "mason-core.platform"
+local path = require "mason-core.path"
+local Result = require "mason-core.result"
+
+local M = {}
+
+---@async
+---@param pkg string
+---@param version string
+---@param opts? { extra_packages?: string[] }
+---@nodiscard
+function M.install(pkg, version, opts)
+ opts = opts or {}
+ log.fmt_debug("gem: install %s %s %s", pkg, version, opts)
+ local ctx = installer.context()
+
+ return ctx.spawn.gem {
+ "install",
+ "--no-user-install",
+ "--no-format-executable",
+ "--install-dir=.",
+ "--bindir=bin",
+ "--no-document",
+ ("%s:%s"):format(pkg, version),
+ opts.extra_packages or vim.NIL,
+ env = {
+ GEM_HOME = ctx.cwd:get(),
+ },
+ }
+end
+
+---@async
+---@param bin string
+---@nodiscard
+function M.create_bin_wrapper(bin)
+ local ctx = installer.context()
+
+ local bin_path = platform.when {
+ unix = function()
+ return path.concat { "bin", bin }
+ end,
+ win = function()
+ return path.concat { "bin", ("%s.bat"):format(bin) }
+ end,
+ }
+
+ if not ctx.fs:file_exists(bin_path) then
+ return Result.failure(("Cannot link Gem executable %q because it doesn't exist."):format(bin))
+ end
+
+ return Result.pcall(ctx.write_shell_exec_wrapper, ctx, bin, path.concat { ctx.package:get_install_path(), bin_path }, {
+ GEM_PATH = platform.when {
+ unix = function()
+ return ("%s:$GEM_PATH"):format(ctx.package:get_install_path())
+ end,
+ win = function()
+ return ("%s;%%GEM_PATH%%"):format(ctx.package:get_install_path())
+ end,
+ },
+ })
+end
+
+return M