Class: Bundler::GemHelpers::PlatformMatch

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

Class Method Summary collapse

Class Method Details

.cpu_match(spec_platform, user_platform) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bundler/gem_helpers.rb', line 73

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



65
66
67
68
69
70
71
# File 'lib/bundler/gem_helpers.rb', line 65

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



85
86
87
88
89
90
91
92
93
# File 'lib/bundler/gem_helpers.rb', line 85

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

.specificity_score(spec_platform, user_platform) ⇒ Object



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

def self.specificity_score(spec_platform, user_platform)
  return -1 if spec_platform == user_platform
  return 1_000_000 if spec_platform.nil? || spec_platform == Gem::Platform::RUBY || user_platform == Gem::Platform::RUBY

  os_match(spec_platform, user_platform) +
    cpu_match(spec_platform, user_platform) * 10 +
    platform_version_match(spec_platform, user_platform) * 100
end