Platform 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/platform.rb +27 -52
  2. metadata +1 -1
@@ -39,60 +39,35 @@
39
39
  # ruby platform.rb
40
40
  #
41
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
-
42
+
43
+ # Each platform is defined as
44
+ # [ /regex/, ::OS, ::IMPL ]
45
+ # define them from most to least specific and
46
+ # [ /.*/, :unknown, :unknown ] should always come last
81
47
  # 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
-
48
+ PLATFORMS = [
49
+ [ /darwin/i, :unix, :macosx ],
50
+ [ /linux/i, :unix, :linux ],
51
+ [ /freebsd/i, :unix, :freebsd ],
52
+ [ /netbsd/i, :unix, :netbsd ],
53
+ [ /cygwin/i, :hybrid, :cygwin ],
54
+ [ /mingw/i, :win32, :mingw ],
55
+ [ /bccwin/i, :win32, :bccwin ],
56
+ [ /vms/i, :vms, :vms ],
57
+ [ /os2/i, :os2, :os2 ],
58
+ [ /.*/, :unknwon, :unknown ]
59
+ ]
60
+ x, OS, IMPL = PLATFORMS.find { |p| RUBY_PLATFORM =~ /#{p[0]}/ }
61
+
95
62
  # What about AMD, Turion, Motorola, etc..?
63
+ ARCHS = [
64
+ [ /i\d86/, :x86 ],
65
+ [ /ia64/, :ia64 ],
66
+ [ /powerpc/, :powerpc ],
67
+ [ /alpha/, :alpha ],
68
+ [ /.*/, :unknown ]
69
+ ]
70
+ x, ARCH = ARCHS.find { |a| RUBY_PLATFORM =~ /#{a[0]}/}
96
71
 
97
72
  end
98
73
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: Platform
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
6
+ version: 0.3.0
7
7
  date: 2005-06-29
8
8
  summary: Hopefully robust platform sensing
9
9
  require_paths: