Method: Bundler::GemVersionPromoter#sort_versions

Defined in:
lib/bundler/gem_version_promoter.rb

#sort_versions(package, specs) ⇒ Specification

Given a Resolver::Package and an Array of Specifications of available versions for a gem, this method will return the Array of Specifications sorted in an order to give preference to the current level (:major, :minor or :patch) when resolution is deciding what versions best resolve all dependencies in the bundle.

Parameters:

  • package (Resolver::Package)

    The package being resolved.

  • specs (Specification)

    An array of Specifications for the package.

Returns:

  • (Specification)

    A new instance of the Specification Array sorted.

[View source]

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bundler/gem_version_promoter.rb', line 54

def sort_versions(package, specs)
  locked_version = package.locked_version

  result = specs.sort do |a, b|
    unless package.prerelease_specified? || pre?
      a_pre = a.prerelease?
      b_pre = b.prerelease?

      next 1 if a_pre && !b_pre
      next -1 if b_pre && !a_pre
    end

    if major? || locked_version.nil?
      b <=> a
    elsif either_version_older_than_locked?(a, b, locked_version)
      b <=> a
    elsif segments_do_not_match?(a, b, :major)
      a <=> b
    elsif !minor? && segments_do_not_match?(a, b, :minor)
      a <=> b
    else
      b <=> a
    end
  end
  post_sort(result, package.unlock?, locked_version)
end