Class: Bundler::Resolver::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/resolver/package.rb

Overview

Represents a gem being resolved, in a format PubGrub likes.

The class holds the following information:

  • Platforms this gem will be resolved on.

  • The locked version of this gem resolution should favor (if any).

  • Whether the gem should be unlocked to its latest version.

  • The dependency explicit set in the Gemfile for this gem (if any).

Direct Known Subclasses

Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, platforms, locked_specs:, unlock:, prerelease: false, dependency: nil) ⇒ Package

Returns a new instance of Package.



18
19
20
21
22
23
24
25
26
# File 'lib/bundler/resolver/package.rb', line 18

def initialize(name, platforms, locked_specs:, unlock:, prerelease: false, dependency: nil)
  @name = name
  @platforms = platforms
  @locked_version = locked_specs[name].first&.version
  @unlock = unlock
  @dependency = dependency || Dependency.new(name, @locked_version)
  @top_level = !dependency.nil?
  @prerelease = @dependency.prerelease? || @locked_version&.prerelease? || prerelease ? :consider_first : :ignore
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



16
17
18
# File 'lib/bundler/resolver/package.rb', line 16

def dependency
  @dependency
end

#locked_versionObject (readonly)

Returns the value of attribute locked_version.



16
17
18
# File 'lib/bundler/resolver/package.rb', line 16

def locked_version
  @locked_version
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/bundler/resolver/package.rb', line 16

def name
  @name
end

#platformsObject (readonly)

Returns the value of attribute platforms.



16
17
18
# File 'lib/bundler/resolver/package.rb', line 16

def platforms
  @platforms
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/bundler/resolver/package.rb', line 48

def ==(other)
  self.class == other.class && @name == other.name
end

#consider_prereleases!Object



68
69
70
# File 'lib/bundler/resolver/package.rb', line 68

def consider_prereleases!
  @prerelease = :consider_last
end

#current_platform?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/bundler/resolver/package.rb', line 76

def current_platform?
  @dependency.current_platform?
end

#force_ruby_platform?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/bundler/resolver/package.rb', line 72

def force_ruby_platform?
  @dependency.force_ruby_platform
end

#hashObject



52
53
54
# File 'lib/bundler/resolver/package.rb', line 52

def hash
  @name.hash
end

#ignores_prereleases?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bundler/resolver/package.rb', line 60

def ignores_prereleases?
  @prerelease == :ignore
end

#meta?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bundler/resolver/package.rb', line 44

def meta?
  @name.end_with?("\0")
end

#platform_specs(specs) ⇒ Object



28
29
30
# File 'lib/bundler/resolver/package.rb', line 28

def platform_specs(specs)
  platforms.map {|platform| GemHelpers.select_best_platform_match(specs, platform, prefer_locked: !unlock?) }
end

#prerelease_specified?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bundler/resolver/package.rb', line 64

def prerelease_specified?
  @prerelease == :consider_first
end

#root?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/bundler/resolver/package.rb', line 36

def root?
  false
end

#to_sObject



32
33
34
# File 'lib/bundler/resolver/package.rb', line 32

def to_s
  @name.delete("\0")
end

#top_level?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bundler/resolver/package.rb', line 40

def top_level?
  @top_level
end

#unlock?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/bundler/resolver/package.rb', line 56

def unlock?
  @unlock.empty? || @unlock.include?(name)
end