Class: Bundler::GemHelpers::PlatformMatch

Inherits:
Struct
  • Object
show all
Defined in:
lib/bundler/gem_helpers.rb,
lib/bundler/gem_helpers.rb

Constant Summary collapse

EXACT_MATCH =
new(-1, -1, -1).freeze
WORST_MATCH =
new(1_000_000, 1_000_000, 1_000_000).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cpu_matchObject

Returns the value of attribute cpu_match

Returns:

  • (Object)

    the current value of cpu_match



50
51
52
# File 'lib/bundler/gem_helpers.rb', line 50

def cpu_match
  @cpu_match
end

#os_matchObject

Returns the value of attribute os_match

Returns:

  • (Object)

    the current value of os_match



50
51
52
# File 'lib/bundler/gem_helpers.rb', line 50

def os_match
  @os_match
end

#platform_version_matchObject

Returns the value of attribute platform_version_match

Returns:

  • (Object)

    the current value of platform_version_match



50
51
52
# File 'lib/bundler/gem_helpers.rb', line 50

def platform_version_match
  @platform_version_match
end

Class Method Details

.cpu_match(spec_platform, user_platform) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bundler/gem_helpers.rb', line 76

def self.cpu_match(spec_platform, user_platform)
  if spec_platform.cpu == user_platform.cpu
    0
  elsif spec_platform.cpu == "arm" && user_platform.cpu.to_s.start_with?("arm")
    0
  elsif spec_platform.cpu.nil? || spec_platform.cpu == "universal"
    1
  else
    2
  end
end

.os_match(spec_platform, user_platform) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/bundler/gem_helpers.rb', line 68

def self.os_match(spec_platform, user_platform)
  if spec_platform.os == user_platform.os
    0
  else
    1
  end
end

.platform_version_match(spec_platform, user_platform) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/bundler/gem_helpers.rb', line 88

def self.platform_version_match(spec_platform, user_platform)
  if spec_platform.version == user_platform.version
    0
  elsif spec_platform.version.nil?
    1
  else
    2
  end
end

Instance Method Details

#<=>(other) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bundler/gem_helpers.rb', line 52

def <=>(other)
  return nil unless other.is_a?(PlatformMatch)

  m = os_match <=> other.os_match
  return m unless m.zero?

  m = cpu_match <=> other.cpu_match
  return m unless m.zero?

  m = platform_version_match <=> other.platform_version_match
  m
end