aboutsummaryrefslogtreecommitdiffstats
path: root/bin/with_rubygems
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-02-24 20:23:44 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-02-24 20:23:44 -0600
commit8a06ca5f6e96636e9349617851dd1b0eb8af1bd8 (patch)
tree4dc4ab184d27a56c1139a593492436f9d5375ac0 /bin/with_rubygems
parentc1f6b0ca96a5593e99a7b9133aff88ade1e38918 (diff)
downloadbundler-8a06ca5f6e96636e9349617851dd1b0eb8af1bd8.tar.gz
Add helper script for running with particular rubygems versions
Diffstat (limited to 'bin/with_rubygems')
-rwxr-xr-xbin/with_rubygems35
1 files changed, 35 insertions, 0 deletions
diff --git a/bin/with_rubygems b/bin/with_rubygems
new file mode 100755
index 00000000..666467b1
--- /dev/null
+++ b/bin/with_rubygems
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require "pathname"
+
+def run(*cmd)
+ return if system(*cmd)
+ raise "Running `#{cmd.join(" ")}` failed"
+end
+
+version = ENV.delete("RGV")
+rubygems_path = Pathname.new(__FILE__).join("../../tmp/rubygems").expand_path
+unless rubygems_path.directory?
+ rubygems_path.parent.mkpath unless rubygems_path.directory?
+ run("git", "clone", "https://github.com/rubygems/rubygems.git", rubygems_path.to_s)
+end
+Dir.chdir(rubygems_path) do
+ version = "v#{version}" if version =~ /\A\d/
+ run("git", "checkout", version, "--quiet")
+end if version
+
+ENV["RUBYOPT"] = %(-I#{rubygems_path + "lib"} #{ENV["RUBYOPT"]})
+if cmd = ARGV.first
+ possible_dirs = [
+ Pathname.new(__FILE__) + "..",
+ Pathname.new(__FILE__) + "../../exe",
+ rubygems_path + "bin",
+ ]
+ cmd = possible_dirs.map do |dir|
+ dir.join(cmd).expand_path
+ end.find(&:file?)
+ ARGV[0] = cmd.to_s if cmd
+end
+
+exec(*ARGV) if $0 == __FILE__