Platform 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +52 -0
- data/lib/platform.rb +101 -0
- metadata +39 -0
data/README
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Platform
|
3
|
+
#
|
4
|
+
# author: Matt Mower <self@mattmower.com>
|
5
|
+
# license: LGPL
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# The Platform library offers a simple, reliable, means of
|
9
|
+
# determining what platform Ruby is running on. Underlying
|
10
|
+
# Platform is the RUBY_PLATFORM constant. This library is
|
11
|
+
# parsing this constant for information. You could easily do
|
12
|
+
# this yourself. We've just taken the hassle out of it for
|
13
|
+
# you and hopefully covered a few of the more unusual cases
|
14
|
+
# you mightn't have thought of yourself.
|
15
|
+
#
|
16
|
+
# On the other hand, if you've got cases we haven't please
|
17
|
+
# mail the authors.
|
18
|
+
#
|
19
|
+
# ==Use
|
20
|
+
#
|
21
|
+
# require 'platform'
|
22
|
+
#
|
23
|
+
# defines
|
24
|
+
#
|
25
|
+
# Platform::OS
|
26
|
+
# :unix
|
27
|
+
# :win32
|
28
|
+
# :vms
|
29
|
+
# :os2
|
30
|
+
# :unknown
|
31
|
+
#
|
32
|
+
# Platform::IMPL
|
33
|
+
# :macosx
|
34
|
+
# :linux
|
35
|
+
# :freebsd
|
36
|
+
# :netbsd
|
37
|
+
# :mswin
|
38
|
+
# :cygwin
|
39
|
+
# :mingw
|
40
|
+
# :bccwin
|
41
|
+
# :wince
|
42
|
+
# :vms
|
43
|
+
# :os2
|
44
|
+
# :unknown
|
45
|
+
#
|
46
|
+
# Platform::ARCH
|
47
|
+
# :x86
|
48
|
+
# :ia64
|
49
|
+
# :powerpc
|
50
|
+
# :alpha
|
51
|
+
# :unknown
|
52
|
+
#
|
data/lib/platform.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#
|
2
|
+
# platform.rb: naive platform detection for Ruby
|
3
|
+
# author: Matt Mower <self@mattmower.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
# == Platform
|
7
|
+
#
|
8
|
+
# Platform is a simple module which parses the Ruby constant
|
9
|
+
# RUBY_PLATFORM and works out the OS, it's implementation,
|
10
|
+
# and the architecture it's running on.
|
11
|
+
#
|
12
|
+
# The motivation for writing this was coming across a case where
|
13
|
+
#
|
14
|
+
# +if RUBY_PLATFORM =~ /win/+
|
15
|
+
#
|
16
|
+
# didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
|
17
|
+
#
|
18
|
+
# It is hoped that providing a library for parsing the platform
|
19
|
+
# means that we can cover all the cases and have something which
|
20
|
+
# works reliably 99% of the time.
|
21
|
+
#
|
22
|
+
# Please report any anomalies or new combinations to the author(s).
|
23
|
+
#
|
24
|
+
# == Use
|
25
|
+
#
|
26
|
+
# require "platform"
|
27
|
+
#
|
28
|
+
# defines
|
29
|
+
#
|
30
|
+
# Platform::OS (:unix,:win32,:vms,:os2)
|
31
|
+
# Platform::IMPL (:macosx,:linux,:mswin)
|
32
|
+
# Platform::ARCH (:powerpc,:x86,:alpha)
|
33
|
+
#
|
34
|
+
# if an unknown configuration is encountered any (or all) of
|
35
|
+
# these constant may have the value :unknown.
|
36
|
+
#
|
37
|
+
# To display the combination for your setup run
|
38
|
+
#
|
39
|
+
# ruby platform.rb
|
40
|
+
#
|
41
|
+
module Platform
|
42
|
+
|
43
|
+
if RUBY_PLATFORM =~ /darwin/i
|
44
|
+
OS = :unix
|
45
|
+
IMPL = :macosx
|
46
|
+
elsif RUBY_PLATFORM =~ /linux/i
|
47
|
+
OS = :unix
|
48
|
+
IMPL = :linux
|
49
|
+
elsif RUBY_PLATFORM =~ /freebsd/i
|
50
|
+
OS = :unix
|
51
|
+
IMPL = :freebsd
|
52
|
+
elsif RUBY_PLATFORM =~ /netbsd/i
|
53
|
+
OS = :unix
|
54
|
+
IMPL = :netbsd
|
55
|
+
elsif RUBY_PLATFORM =~ /mswin/i
|
56
|
+
OS = :win32
|
57
|
+
IMPL = :mswin
|
58
|
+
elsif RUBY_PLATFORM =~ /cygwin/i
|
59
|
+
OS = :unix
|
60
|
+
IMPL = :cygwin
|
61
|
+
elsif RUBY_PLATFORM =~ /mingw/i
|
62
|
+
OS = :win32
|
63
|
+
IMPL = :mingw
|
64
|
+
elsif RUBY_PLATFORM =~ /bccwin/i
|
65
|
+
OS = :win32
|
66
|
+
IMPL = :bccwin
|
67
|
+
elsif RUBY_PLATFORM =~ /wince/i
|
68
|
+
OS = :win32
|
69
|
+
IMPL = :wince
|
70
|
+
elsif RUBY_PLATFORM =~ /vms/i
|
71
|
+
OS = :vms
|
72
|
+
IMPL = :vms
|
73
|
+
elsif RUBY_PLATFORM =~ /os2/i
|
74
|
+
OS = :os2
|
75
|
+
IMPL = :os2 # maybe there is some better choice here?
|
76
|
+
else
|
77
|
+
OS = :unknown
|
78
|
+
IMPL = :unknown
|
79
|
+
end
|
80
|
+
|
81
|
+
# whither AIX, SOLARIS, and the other unixen?
|
82
|
+
|
83
|
+
if RUBY_PLATFORM =~ /(i\d86)/i
|
84
|
+
ARCH = :x86
|
85
|
+
elsif RUBY_PLATFORM =~ /ia64/i
|
86
|
+
ARCH = :ia64
|
87
|
+
elsif RUBY_PLATFORM =~ /powerpc/i
|
88
|
+
ARCH = :powerpc
|
89
|
+
elsif RUBY_PLATFORM =~ /alpha/i
|
90
|
+
ARCH = :alpha
|
91
|
+
else
|
92
|
+
ARCH = :unknown
|
93
|
+
end
|
94
|
+
|
95
|
+
# What about AMD, Turion, Motorola, etc..?
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
if __FILE__ == $0
|
100
|
+
puts "Platform OS=#{Platform::OS}, IMPL=#{Platform::IMPL}, ARCH=#{Platform::ARCH}"
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: Platform
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2005-06-29
|
8
|
+
summary: Hopefully robust platform sensing
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: self@mattmower.com
|
12
|
+
homepage: http://rubyforge.org/projects/platform/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: platform
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Matt Mower
|
29
|
+
files:
|
30
|
+
- lib/platform.rb
|
31
|
+
- README
|
32
|
+
test_files: []
|
33
|
+
rdoc_options: []
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
requirements: []
|
39
|
+
dependencies: []
|