88# this file is here to facilitate running it.
99#
1010
11- require " rubygems"
11+ require ' rubygems'
1212
1313m = Module . new do
1414 module_function
@@ -18,45 +18,47 @@ m = Module.new do
1818 end
1919
2020 def env_var_version
21- ENV [ " BUNDLER_VERSION" ]
21+ ENV [ ' BUNDLER_VERSION' ]
2222 end
2323
2424 def cli_arg_version
2525 return unless invoked_as_script? # don't want to hijack other binstubs
26- return unless "update" . start_with? ( ARGV . first || " " ) # must be running `bundle update`
26+ return unless 'update' . start_with? ( ARGV . first || ' ' ) # must be running `bundle update`
27+
2728 bundler_version = nil
2829 update_index = nil
2930 ARGV . each_with_index do |a , i |
30- if update_index && update_index . succ == i && a . match? ( Gem ::Version ::ANCHORED_VERSION_PATTERN )
31- bundler_version = a
32- end
31+ bundler_version = a if update_index && update_index . succ == i && a . match? ( Gem ::Version ::ANCHORED_VERSION_PATTERN )
3332 next unless a =~ /\A --bundler(?:[= ](#{ Gem ::Version ::VERSION_PATTERN } ))?\z /
34- bundler_version = $1
33+
34+ bundler_version = Regexp . last_match ( 1 )
3535 update_index = i
3636 end
3737 bundler_version
3838 end
3939
4040 def gemfile
41- gemfile = ENV [ " BUNDLE_GEMFILE" ]
41+ gemfile = ENV [ ' BUNDLE_GEMFILE' ]
4242 return gemfile if gemfile && !gemfile . empty?
4343
44- File . expand_path ( " ../Gemfile" , __dir__ )
44+ File . expand_path ( ' ../Gemfile' , __dir__ )
4545 end
4646
4747 def lockfile
4848 lockfile =
4949 case File . basename ( gemfile )
50- when " gems.rb" then gemfile . sub ( /\. rb$/ , " .locked" )
50+ when ' gems.rb' then gemfile . sub ( /\. rb$/ , ' .locked' )
5151 else "#{ gemfile } .lock"
5252 end
5353 File . expand_path ( lockfile )
5454 end
5555
5656 def lockfile_version
5757 return unless File . file? ( lockfile )
58+
5859 lockfile_contents = File . read ( lockfile )
5960 return unless lockfile_contents =~ /\n \n BUNDLED WITH\n \s {2,}(#{ Gem ::Version ::VERSION_PATTERN } )\n /
61+
6062 Regexp . last_match ( 1 )
6163 end
6264
@@ -76,20 +78,24 @@ m = Module.new do
7678 end
7779
7880 def load_bundler!
79- ENV [ " BUNDLE_GEMFILE" ] ||= gemfile
81+ ENV [ ' BUNDLE_GEMFILE' ] ||= gemfile
8082
8183 activate_bundler
8284 end
8385
8486 def activate_bundler
8587 gem_error = activation_error_handling do
86- gem " bundler" , bundler_requirement
88+ gem ' bundler' , bundler_requirement
8789 end
8890 return if gem_error . nil?
91+
8992 require_error = activation_error_handling do
90- require "bundler/version"
93+ require 'bundler/version'
94+ end
95+ if require_error . nil? && Gem ::Requirement . new ( bundler_requirement ) . satisfied_by? ( Gem ::Version . new ( Bundler ::VERSION ) )
96+ return
9197 end
92- return if require_error . nil? && Gem :: Requirement . new ( bundler_requirement ) . satisfied_by? ( Gem :: Version . new ( Bundler :: VERSION ) )
98+
9399 warn "Activating bundler (#{ bundler_requirement } ) failed:\n #{ gem_error . message } \n \n To install the version of bundler this project requires, run `gem install bundler -v '#{ bundler_requirement } '`"
94100 exit 42
95101 end
104110
105111m . load_bundler!
106112
107- if m . invoked_as_script?
108- load Gem . bin_path ( "bundler" , "bundle" )
109- end
113+ load Gem . bin_path ( 'bundler' , 'bundle' ) if m . invoked_as_script?
0 commit comments