123456789_123456789_123456789_123456789_123456789_

Class: Gem::Platform

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/rubygems_ext.rb

Constant Summary

Class Method Summary

Class Method Details

.cpu_match(spec_platform, user_platform) (private)

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 148

def 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

.generic(platform)

Returns the generic platform for the given platform.

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 78

def generic(platform)
  return Gem::Platform::RUBY if platform.nil? || platform == Gem::Platform::RUBY

  GENERIC_CACHE[platform] ||= begin
    found = GENERICS.find do |match|
      platform === match
    end
    found || Gem::Platform::RUBY
  end
end

.os_match(spec_platform, user_platform) (private)

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 140

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

.platform_specificity_match(spec_platform, user_platform)

Returns the platform specificity match for the given spec platform and user platform.

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 92

def platform_specificity_match(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 +
    version_match(spec_platform, user_platform) * 100
end

.same_deps?(spec, exemplary_spec) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 134

def same_deps?(spec, exemplary_spec)
  spec.required_ruby_version == exemplary_spec.required_ruby_version &&
    spec.required_rubygems_version == exemplary_spec.required_rubygems_version &&
    spec.dependencies.sort == exemplary_spec.dependencies.sort
end

.same_specificity?(platform, spec, exemplary_spec) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 130

def same_specificity?(platform, spec, exemplary_spec)
  platform_specificity_match(spec.platform, platform) == platform_specificity_match(exemplary_spec.platform, platform)
end

.sort_and_filter_best_platform_match(matching, platform)

Sorts and filters the best platform match for the given matching specs and platform.

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 104

def sort_and_filter_best_platform_match(matching, platform)
  return matching if matching.one?

  exact = matching.select {|spec| spec.platform == platform }
  return exact if exact.any?

  sorted_matching = sort_best_platform_match(matching, platform)
  exemplary_spec = sorted_matching.first

  sorted_matching.take_while {|spec| same_specificity?(platform, spec, exemplary_spec) && same_deps?(spec, exemplary_spec) }
end

.sort_best_platform_match(matching, platform)

Sorts the best platform match for the given matching specs and platform.

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 119

def sort_best_platform_match(matching, platform)
  matching.sort_by.with_index do |spec, i|
    [
      platform_specificity_match(spec.platform, platform),
      i, # for stable sort
    ]
  end
end

.version_match(spec_platform, user_platform) (private)

[ GitHub ]

  
# File 'lib/bundler/rubygems_ext.rb', line 160

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