1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require "rubygems"
m = Module.new do
extend self
def gemfile
File.expand_path("../Gemfile", __dir__)
end
def lockfile
"#{gemfile}.lock"
end
def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
regexp = /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
regexp.match(lockfile_contents)[1]
end
def bundler_version
@bundler_version ||= lockfile_version
end
def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
activate_bundler(bundler_version)
end
def activate_bundler(bundler_version)
gem "bundler", bundler_version
end
end
m.load_bundler!
|