-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
642 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "rubygems" | ||
|
||
m = Module.new do | ||
extend self | ||
|
||
def invoked_as_script? | ||
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__) | ||
end | ||
|
||
def cli_arg_version | ||
return unless invoked_as_script? # don't want to hijack other binstubs | ||
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` | ||
|
||
bundler_version = nil | ||
update_index = nil | ||
ARGV.each_with_index do |a, i| | ||
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN | ||
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ | ||
|
||
bundler_version = Regexp.last_match(1) || ">= 0.a" | ||
update_index = i | ||
end | ||
bundler_version | ||
end | ||
|
||
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 ||= cli_arg_version || lockfile_version | ||
end | ||
|
||
def load_bundler! | ||
activate_bundler(bundler_version) | ||
end | ||
|
||
def activate_bundler(bundler_version) | ||
gem "bundler", bundler_version | ||
end | ||
end | ||
|
||
m.load_bundler! | ||
|
||
load Gem.bin_path("bundler", "bundle") if m.invoked_as_script? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.