Class: Bundler::Resolver::Candidate
- Inherits:
-
Object
- Object
- Bundler::Resolver::Candidate
- 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 the 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
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #canonical? ⇒ Boolean
- #dependencies ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(version, specs: []) ⇒ Candidate
constructor
A new instance of Candidate.
- #prerelease? ⇒ Boolean
- #segments ⇒ Object
- #sort_obj ⇒ Object
- #to_s ⇒ Object
- #to_specs(package) ⇒ Object
Constructor Details
#initialize(version, specs: []) ⇒ Candidate
Returns a new instance of Candidate.
27 28 29 30 31 32 |
# File 'lib/bundler/resolver/candidate.rb', line 27 def initialize(version, specs: []) @spec_group = Resolver::SpecGroup.new(specs) @platforms = specs.map(&:platform).sort_by(&:to_s).uniq @version = Gem::Version.new(version) @ruby_only = @platforms == [Gem::Platform::RUBY] end |
Instance Attribute Details
#version ⇒ Object (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
60 61 62 63 64 65 |
# File 'lib/bundler/resolver/candidate.rb', line 60 def <=>(other) return unless other.is_a?(self.class) return @version <=> other.version unless canonical? && other.canonical? sort_obj <=> other.sort_obj end |
#==(other) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/bundler/resolver/candidate.rb', line 67 def ==(other) return unless other.is_a?(self.class) return @version == other.version unless canonical? && other.canonical? sort_obj == other.sort_obj end |
#canonical? ⇒ Boolean
56 57 58 |
# File 'lib/bundler/resolver/candidate.rb', line 56 def canonical? !@spec_group.empty? end |
#dependencies ⇒ Object
34 35 36 |
# File 'lib/bundler/resolver/candidate.rb', line 34 def dependencies @spec_group.dependencies end |
#eql?(other) ⇒ Boolean
74 75 76 77 78 79 |
# File 'lib/bundler/resolver/candidate.rb', line 74 def eql?(other) return unless other.is_a?(self.class) return @version.eql?(other.version) unless canonical? || other.canonical? sort_obj.eql?(other.sort_obj) end |
#hash ⇒ Object
81 82 83 |
# File 'lib/bundler/resolver/candidate.rb', line 81 def hash sort_obj.hash end |
#prerelease? ⇒ Boolean
44 45 46 |
# File 'lib/bundler/resolver/candidate.rb', line 44 def prerelease? @version.prerelease? end |
#segments ⇒ Object
48 49 50 |
# File 'lib/bundler/resolver/candidate.rb', line 48 def segments @version.segments end |
#sort_obj ⇒ Object
52 53 54 |
# File 'lib/bundler/resolver/candidate.rb', line 52 def sort_obj [@version, @ruby_only ? -1 : 1] end |
#to_s ⇒ Object
85 86 87 88 89 |
# File 'lib/bundler/resolver/candidate.rb', line 85 def to_s return @version.to_s if @platforms.empty? || @ruby_only "#{@version} (#{@platforms.join(", ")})" end |
#to_specs(package) ⇒ Object
38 39 40 41 42 |
# File 'lib/bundler/resolver/candidate.rb', line 38 def to_specs(package) return [] if package. @spec_group.to_specs(package.force_ruby_platform?) end |