| Class | Platform |
| In: |
lib/more/facets/platform.rb
|
| Parent: | Object |
| RbConfig | = | Config unless defined? ::RbConfig | ||
| 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/more/facets/platform.rb, line 35
35: def self.const_missing(name) # TODO remove six months from 2007/12
36: if DEPRECATED_CONSTS.include? name then
37: raise NameError, "#{name} has been removed, use CURRENT instead"
38: else
39: super
40: end
41: end
# File lib/more/facets/platform.rb, line 43
43: def self.local
44: arch = RbConfig::CONFIG['arch']
45: arch = "#{arch}_60" if arch =~ /mswin32$/
46: @local ||= new(arch)
47: end
# File lib/more/facets/platform.rb, line 49
49: def self.match(platform)
50: supported.any? do |local_platform|
51: platform.nil? or local_platform == platform or
52: (local_platform != Platform::RUBY and local_platform =~ platform)
53: end
54: end
# File lib/more/facets/platform.rb, line 67
67: def initialize(arch)
68: case arch
69: when Array then
70: @cpu, @os, @version = arch
71: when String then
72: arch = arch.split '-'
73:
74: if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
75: extra = arch.pop
76: arch.last << "-#{extra}"
77: end
78:
79: cpu = arch.shift
80:
81: @cpu = case cpu
82: when /i\d86/ then 'x86'
83: else cpu
84: end
85:
86: if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line
87: @os, @version = arch
88: return
89: end
90:
91: os, = arch
92: @cpu, os = nil, cpu if os.nil? # legacy jruby
93:
94: @os, @version = case os
95: when /aix(\d+)/ then [ 'aix', $1 ]
96: when /cygwin/ then [ 'cygwin', nil ]
97: when /darwin(\d+)?/ then [ 'darwin', $1 ]
98: when /freebsd(\d+)/ then [ 'freebsd', $1 ]
99: when /hpux(\d+)/ then [ 'hpux', $1 ]
100: when /^java$/, /^jruby$/ then [ 'java', nil ]
101: when /^java([\d.]*)/ then [ 'java', $1 ]
102: when /linux/ then [ 'linux', $1 ]
103: when /mingw32/ then [ 'mingw32', nil ]
104: when /(mswin\d+)(\_(\d+))?/ then
105: os, version = $1, $3
106: @cpu = 'x86' if @cpu.nil? and os =~ /32$/
107: [os, version]
108: when /netbsdelf/ then [ 'netbsdelf', nil ]
109: when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ]
110: when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ]
111: # test
112: when /^(\w+_platform)(\d+)/ then [ $1, $2 ]
113: else [ 'unknown', nil ]
114: end
115: when Platform then
116: @cpu = arch.cpu
117: @os = arch.os
118: @version = arch.version
119: else
120: raise ArgumentError, "invalid argument #{arch.inspect}"
121: end
122: end
# File lib/more/facets/platform.rb, line 136
136: def ==(other)
137: self.class === other and
138: @cpu == other.cpu and @os == other.os and @version == other.version
139: end
# File lib/more/facets/platform.rb, line 141
141: def ===(other)
142: return nil unless Platform === other
143:
144: # cpu
145: (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
146:
147: # os
148: @os == other.os and
149:
150: # version
151: (@version.nil? or other.version.nil? or @version == other.version)
152: end
# File lib/more/facets/platform.rb, line 154
154: def =~(other)
155: case other
156: when Platform then # nop
157: when String then
158: # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
159: other = case other
160: when /^i686-darwin(\d)/ then ['x86', 'darwin', $1]
161: when /^i\d86-linux/ then ['x86', 'linux', nil]
162: when 'java', 'jruby' then [nil, 'java', nil]
163: when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2]
164: when 'powerpc-darwin' then ['powerpc', 'darwin', nil]
165: when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1]
166: when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8']
167: when /universal-darwin(\d)/ then ['universal', 'darwin', $1]
168: else other
169: end
170:
171: other = Platform.new other
172: else
173: return nil
174: end
175:
176: self === other
177: end
# File lib/more/facets/platform.rb, line 200
200: def big_endian?
201: ByteOrder.big_endian?
202: end
Determine byte order of underlying machine.
# File lib/more/facets/platform.rb, line 192
192: def byte_order
193: ByteOrder.byte_order
194: end
# File lib/more/facets/platform.rb, line 124
124: def inspect
125: "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
126: end
# File lib/more/facets/platform.rb, line 196
196: def little_endian?
197: ByteOrder.little_endian?
198: end