Class: Bundler::Resolver::Candidate

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/bundler/resolver/candidate.rb

Overview

This class is a PubGrub compatible “Version” class that takes Bundler resolution complexities into account.

Each Resolver::Candidate has a underlying ‘Gem::Version` plus a set of platforms. For example, 1.1.0-x86_64-linux is a different resolution candidate from 1.1.0 (generic). This is because different platform variants of the same gem version can bring different dependencies, so they need to be considered separately.

Some candidates may also keep some information explicitly about the package they refer to. These candidates are referred to as “canonical” and are used when materializing resolution results back into RubyGems specifications that can be installed, written to lock files, and so on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, specs: []) ⇒ Candidate

Returns a new instance of Candidate.



27
28
29
30
31
# File 'lib/bundler/resolver/candidate.rb', line 27

def initialize(version, specs: [])
  @spec_group = Resolver::SpecGroup.new(specs)
  @version = Gem::Version.new(version)
  @ruby_only = specs.map(&:platform).uniq == [Gem::Platform::RUBY]
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



25
26
27
# File 'lib/bundler/resolver/candidate.rb', line 25

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
70
71
# File 'lib/bundler/resolver/candidate.rb', line 67

def <=>(other)
  return unless other.is_a?(self.class)

  sort_obj <=> other.sort_obj
end

#==(other) ⇒ Object



73
74
75
76
77
# File 'lib/bundler/resolver/candidate.rb', line 73

def ==(other)
  return unless other.is_a?(self.class)

  sort_obj == other.sort_obj
end

#dependenciesObject



33
34
35
# File 'lib/bundler/resolver/candidate.rb', line 33

def dependencies
  @spec_group.dependencies
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/bundler/resolver/candidate.rb', line 79

def eql?(other)
  return unless other.is_a?(self.class)

  sort_obj.eql?(other.sort_obj)
end

#generic!Object



43
44
45
46
47
# File 'lib/bundler/resolver/candidate.rb', line 43

def generic!
  @ruby_only = true

  self
end

#hashObject



85
86
87
# File 'lib/bundler/resolver/candidate.rb', line 85

def hash
  sort_obj.hash
end

#platform_specific!Object



49
50
51
52
53
# File 'lib/bundler/resolver/candidate.rb', line 49

def platform_specific!
  @ruby_only = false

  self
end

#prerelease?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/bundler/resolver/candidate.rb', line 55

def prerelease?
  @version.prerelease?
end

#segmentsObject



59
60
61
# File 'lib/bundler/resolver/candidate.rb', line 59

def segments
  @version.segments
end

#sort_objObject



63
64
65
# File 'lib/bundler/resolver/candidate.rb', line 63

def sort_obj
  [@version, @ruby_only ? -1 : 1]
end

#to_sObject



89
90
91
# File 'lib/bundler/resolver/candidate.rb', line 89

def to_s
  @version.to_s
end

#to_specs(package) ⇒ Object



37
38
39
40
41
# File 'lib/bundler/resolver/candidate.rb', line 37

def to_specs(package)
  return [] if package.meta?

  @spec_group.to_specs(package.force_ruby_platform?)
end