Module: Gem::BundlerVersionFinder

Defined in:
lib/rubygems/bundler_version_finder.rb

Class Method Summary collapse

Class Method Details

.bundler_versionObject


6
7
8
9
10
11
12
# File 'lib/rubygems/bundler_version_finder.rb', line 6

def self.bundler_version
  version, _ = bundler_version_with_reason

  return unless version

  Gem::Version.new(version)
end

.bundler_version_with_reasonObject


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubygems/bundler_version_finder.rb', line 14

def self.bundler_version_with_reason
  if v = ENV["BUNDLER_VERSION"]
    return [v, "`$BUNDLER_VERSION`"]
  end
  if v = bundle_update_bundler_version
    return if v == true
    return [v, "`bundle update --bundler`"]
  end
  v, lockfile = lockfile_version
  if v
    return [v, "your #{lockfile}"]
  end
end

.compatible?(spec) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
40
41
42
# File 'lib/rubygems/bundler_version_finder.rb', line 37

def self.compatible?(spec)
  return true unless spec.name == "bundler".freeze
  return true unless bundler_version = self.bundler_version

  spec.version.segments.first == bundler_version.segments.first
end

.filter!(specs) ⇒ Object


44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/bundler_version_finder.rb', line 44

def self.filter!(specs)
  return unless bundler_version = self.bundler_version

  specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first }

  exact_match_index = specs.find_index { |spec| spec.version == bundler_version }
  return unless exact_match_index

  specs.unshift(specs.delete_at(exact_match_index))
end

.missing_version_messageObject


28
29
30
31
32
33
34
35
# File 'lib/rubygems/bundler_version_finder.rb', line 28

def self.missing_version_message
  return unless vr = bundler_version_with_reason
  <<-EOS
Could not find 'bundler' (#{vr.first}) required by #{vr.last}.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:#{vr.first}`
  EOS
end