Class | Gem::Platform |
In: |
lib/rubygems/platform.rb
|
Parent: | Object |
Available list of platforms for targeting Gem installations.
DEPRECATED_CONSTS | = | [ :DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX | ||
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 25 25: def self.const_missing(name) # TODO remove six months from 2007/12 26: if DEPRECATED_CONSTS.include? name then 27: raise NameError, "#{name} has been removed, use CURRENT instead" 28: else 29: super 30: end 31: end
# File lib/rubygems/platform.rb, line 33 33: def self.local 34: arch = Gem::ConfigMap[:arch] 35: arch = "#{arch}_60" if arch =~ /mswin32$/ 36: @local ||= new(arch) 37: end
# File lib/rubygems/platform.rb, line 39 39: def self.match(platform) 40: Gem.platforms.any? do |local_platform| 41: platform.nil? or local_platform == platform or 42: (local_platform != Gem::Platform::RUBY and local_platform =~ platform) 43: end 44: end
# File lib/rubygems/platform.rb, line 57 57: def initialize(arch) 58: case arch 59: when Array then 60: @cpu, @os, @version = arch 61: when String then 62: arch = arch.split '-' 63: 64: if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu 65: extra = arch.pop 66: arch.last << "-#{extra}" 67: end 68: 69: cpu = arch.shift 70: 71: @cpu = case cpu 72: when /i\d86/ then 'x86' 73: else cpu 74: end 75: 76: if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line 77: @os, @version = arch 78: return 79: end 80: 81: os, = arch 82: @cpu, os = nil, cpu if os.nil? # legacy jruby 83: 84: @os, @version = case os 85: when /aix(\d+)/ then [ 'aix', $1 ] 86: when /cygwin/ then [ 'cygwin', nil ] 87: when /darwin(\d+)?/ then [ 'darwin', $1 ] 88: when /freebsd(\d+)/ then [ 'freebsd', $1 ] 89: when /hpux(\d+)/ then [ 'hpux', $1 ] 90: when /^java$/, /^jruby$/ then [ 'java', nil ] 91: when /^java([\d.]*)/ then [ 'java', $1 ] 92: when /linux/ then [ 'linux', $1 ] 93: when /mingw32/ then [ 'mingw32', nil ] 94: when /(mswin\d+)(\_(\d+))?/ then 95: os, version = $1, $3 96: @cpu = 'x86' if @cpu.nil? and os =~ /32$/ 97: [os, version] 98: when /netbsdelf/ then [ 'netbsdelf', nil ] 99: when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ] 100: when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ] 101: # test 102: when /^(\w+_platform)(\d+)/ then [ $1, $2 ] 103: else [ 'unknown', nil ] 104: end 105: when Gem::Platform then 106: @cpu = arch.cpu 107: @os = arch.os 108: @version = arch.version 109: else 110: raise ArgumentError, "invalid argument #{arch.inspect}" 111: end 112: 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 130 130: def ==(other) 131: self.class === other and 132: @cpu == other.cpu and @os == other.os and @version == other.version 133: 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 140 140: def ===(other) 141: return nil unless Gem::Platform === other 142: 143: # cpu 144: (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and 145: 146: # os 147: @os == other.os and 148: 149: # version 150: (@version.nil? or other.version.nil? or @version == other.version) 151: 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 157 157: def =~(other) 158: case other 159: when Gem::Platform then # nop 160: when String then 161: # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007 162: other = case other 163: when /^i686-darwin(\d)/ then ['x86', 'darwin', $1] 164: when /^i\d86-linux/ then ['x86', 'linux', nil] 165: when 'java', 'jruby' then [nil, 'java', nil] 166: when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2] 167: when 'powerpc-darwin' then ['powerpc', 'darwin', nil] 168: when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1] 169: when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8'] 170: when /universal-darwin(\d)/ then ['universal', 'darwin', $1] 171: else other 172: end 173: 174: other = Gem::Platform.new other 175: else 176: return nil 177: end 178: 179: self === other 180: end
# File lib/rubygems/platform.rb, line 114 114: def inspect 115: "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a] 116: end