Class | Gem::Platform |
In: |
lib/rubygems/platform.rb
|
Parent: | Object |
Available list of platforms for targeting Gem installations.
RUBY | = | 'ruby' | A pure-ruby gem that may use Gem::Specification#extensions to build binary files. | |
CURRENT | = | 'current' | A platform-specific gem that is built for the packaging ruby‘s platform. This will be replaced with Gem::Platform::local. |
cpu | [RW] | |
os | [RW] | |
version | [RW] |
# File lib/rubygems/platform.rb, line 16 16: def self.local 17: arch = Gem::ConfigMap[:arch] 18: arch = "#{arch}_60" if arch =~ /mswin32$/ 19: @local ||= new(arch) 20: end
# File lib/rubygems/platform.rb, line 22 22: def self.match(platform) 23: Gem.platforms.any? do |local_platform| 24: platform.nil? or local_platform == platform or 25: (local_platform != Gem::Platform::RUBY and local_platform =~ platform) 26: end 27: end
# File lib/rubygems/platform.rb, line 40 40: def initialize(arch) 41: case arch 42: when Array then 43: @cpu, @os, @version = arch 44: when String then 45: arch = arch.split '-' 46: 47: if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu 48: extra = arch.pop 49: arch.last << "-#{extra}" 50: end 51: 52: cpu = arch.shift 53: 54: @cpu = case cpu 55: when /i\d86/ then 'x86' 56: else cpu 57: end 58: 59: if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line 60: @os, @version = arch 61: return 62: end 63: 64: os, = arch 65: @cpu, os = nil, cpu if os.nil? # legacy jruby 66: 67: @os, @version = case os 68: when /aix(\d+)/ then [ 'aix', $1 ] 69: when /cygwin/ then [ 'cygwin', nil ] 70: when /darwin(\d+)?/ then [ 'darwin', $1 ] 71: when /^macruby$/ then [ 'macruby', nil ] 72: when /freebsd(\d+)/ then [ 'freebsd', $1 ] 73: when /hpux(\d+)/ then [ 'hpux', $1 ] 74: when /^java$/, /^jruby$/ then [ 'java', nil ] 75: when /^java([\d.]*)/ then [ 'java', $1 ] 76: when /^dotnet$/ then [ 'dotnet', nil ] 77: when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ] 78: when /linux/ then [ 'linux', $1 ] 79: when /mingw32/ then [ 'mingw32', nil ] 80: when /(mswin\d+)(\_(\d+))?/ then 81: os, version = $1, $3 82: @cpu = 'x86' if @cpu.nil? and os =~ /32$/ 83: [os, version] 84: when /netbsdelf/ then [ 'netbsdelf', nil ] 85: when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ] 86: when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ] 87: # test 88: when /^(\w+_platform)(\d+)/ then [ $1, $2 ] 89: else [ 'unknown', nil ] 90: end 91: when Gem::Platform then 92: @cpu = arch.cpu 93: @os = arch.os 94: @version = arch.version 95: else 96: raise ArgumentError, "invalid argument #{arch.inspect}" 97: end 98: end
Is other equal to this platform? Two platforms are equal if they have the same CPU, OS and version.
# File lib/rubygems/platform.rb, line 120 120: def ==(other) 121: self.class === other and to_a == other.to_a 122: end
Does other match this platform? Two platforms match if they have the same CPU, or either has a CPU of ‘universal’, they have the same OS, and they have the same version, or either has no version.
# File lib/rubygems/platform.rb, line 135 135: def ===(other) 136: return nil unless Gem::Platform === other 137: 138: # cpu 139: (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and 140: 141: # os 142: @os == other.os and 143: 144: # version 145: (@version.nil? or other.version.nil? or @version == other.version) 146: end
Does other match this platform? If other is a String it will be converted to a Gem::Platform first. See #=== for matching rules.
# File lib/rubygems/platform.rb, line 152 152: def =~(other) 153: case other 154: when Gem::Platform then # nop 155: when String then 156: # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007 157: other = case other 158: when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] 159: when /^i\d86-linux/ then ['x86', 'linux', nil ] 160: when 'java', 'jruby' then [nil, 'java', nil ] 161: when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ] 162: when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] 163: when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] 164: when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] 165: when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ] 166: when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ] 167: else other 168: end 169: 170: other = Gem::Platform.new other 171: else 172: return nil 173: end 174: 175: self === other 176: end
# File lib/rubygems/platform.rb, line 100 100: def inspect 101: "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a] 102: end