os 0.7.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +14 -0
- data/.document +5 -5
- data/.gitignore +21 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +31 -0
- data/README.rdoc +62 -47
- data/Rakefile +24 -26
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/lib/os.rb +218 -172
- data/os.gemspec +60 -0
- data/spec/linux_spec.rb +38 -0
- data/spec/{spec.os.rb → os_spec.rb} +145 -122
- data/spec/osx_spec.rb +29 -0
- data/spec/spec_helper.rb +9 -0
- metadata +61 -45
data/.autotest
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# autotest config for rspec
|
2
|
+
# see: https://github.com/rspec/rspec/wiki/autotest
|
3
|
+
Autotest.add_hook(:initialize) {|at|
|
4
|
+
at.add_exception %r{^\.git} # ignore Version Control System
|
5
|
+
at.add_exception %r{^pkg} # ignore gem pkg dir
|
6
|
+
# at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
|
7
|
+
# at.clear_mappings # take out the default (test/test*rb)
|
8
|
+
## include specs
|
9
|
+
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
|
10
|
+
Dir['spec/**/*_spec.rb']
|
11
|
+
}
|
12
|
+
nil
|
13
|
+
}
|
14
|
+
|
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
README.rdoc
|
2
|
-
lib/**/*.rb
|
3
|
-
bin/*
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE
|
1
|
+
README.rdoc
|
2
|
+
lib/**/*.rb
|
3
|
+
bin/*
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
os (0.7.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
git (1.2.5)
|
11
|
+
jeweler (1.6.0)
|
12
|
+
bundler (~> 1.0.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rake (0.8.7)
|
16
|
+
rspec (2.5.0)
|
17
|
+
rspec-core (~> 2.5.0)
|
18
|
+
rspec-expectations (~> 2.5.0)
|
19
|
+
rspec-mocks (~> 2.5.0)
|
20
|
+
rspec-core (2.5.1)
|
21
|
+
rspec-expectations (2.5.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
jeweler
|
30
|
+
os!
|
31
|
+
rspec (>= 2.0)
|
data/README.rdoc
CHANGED
@@ -1,47 +1,62 @@
|
|
1
|
-
The OS gem allows for some easy telling if you're on windows or not.
|
2
|
-
|
3
|
-
require 'os'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
1
|
+
The OS gem allows for some easy telling if you're on windows or not.
|
2
|
+
|
3
|
+
require 'os'
|
4
|
+
|
5
|
+
>> OS.windows?
|
6
|
+
=> true # also OS.doze?
|
7
|
+
|
8
|
+
>> OS.bits
|
9
|
+
=> 32
|
10
|
+
|
11
|
+
>> OS.java?
|
12
|
+
=> true # if you're running in jruby also OS.jruby?
|
13
|
+
|
14
|
+
>> OS.ruby_bin
|
15
|
+
=> "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
|
16
|
+
|
17
|
+
>> OS.posix?
|
18
|
+
=> false
|
19
|
+
|
20
|
+
>> OS.mac?
|
21
|
+
=> false
|
22
|
+
|
23
|
+
>> OS.java? # same as OS.jruby?
|
24
|
+
=> true
|
25
|
+
|
26
|
+
>> OS.dev_null
|
27
|
+
=> "NUL" # or "/dev/null" depending on which platform
|
28
|
+
|
29
|
+
>> OS.rss_bytes
|
30
|
+
=> 12300033 # rss bytes this process is using currently, works in Linux/windows
|
31
|
+
|
32
|
+
>> puts OS.report
|
33
|
+
==> # a yaml report of helpful values
|
34
|
+
---
|
35
|
+
arch: x86_64-darwin10.6.0
|
36
|
+
target_os: darwin10.6.0
|
37
|
+
target_vendor: apple
|
38
|
+
target_cpu: x86_64
|
39
|
+
target: x86_64-apple-darwin10.6.0
|
40
|
+
host_os: darwin10.6.0
|
41
|
+
host_vendor: apple
|
42
|
+
host_cpu: i386
|
43
|
+
host: i386-apple-darwin10.6.0
|
44
|
+
RUBY_PLATFORM: x86_64-darwin10.6.0
|
45
|
+
|
46
|
+
If there are any other features you'd like, let me know.
|
47
|
+
|
48
|
+
github.com/rdp/os for feedback et al
|
49
|
+
|
50
|
+
Related projects:
|
51
|
+
|
52
|
+
rubygems:
|
53
|
+
Gem::Platform.local
|
54
|
+
Gem.ruby
|
55
|
+
|
56
|
+
facets gem (similar to rubygems, above)
|
57
|
+
require 'facets/platform'
|
58
|
+
Platform.local
|
59
|
+
|
60
|
+
the "platform" gem, itself (different gem)
|
61
|
+
|
62
|
+
The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.
|
data/Rakefile
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
gem.
|
14
|
-
gem.
|
15
|
-
gem.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
26
|
-
end
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "os"
|
8
|
+
gem.summary = %Q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
|
9
|
+
gem.description = %Q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
|
10
|
+
gem.email = "rogerpack2005@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/rdp/os"
|
12
|
+
gem.authors = ["rdp", "David McCullars"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
# gem.add_development_dependency "fast_require"
|
15
|
+
gem.add_development_dependency "rspec", ">= 2.0"
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rspec/core/rake_task'
|
22
|
+
RSpec::Core::RakeTask.new(:spec)
|
23
|
+
task :default => :spec
|
24
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/lib/os.rb
CHANGED
@@ -1,172 +1,218 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
else
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def self.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
# a set of friendly files for determining your Ruby runtime
|
5
|
+
# treats cygwin as linux
|
6
|
+
# also treats IronRuby on mono as...linux
|
7
|
+
class OS
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
@config ||= RbConfig::CONFIG
|
12
|
+
end
|
13
|
+
|
14
|
+
# true if on windows [and/or jruby]
|
15
|
+
# false if on linux or cygwin on windows
|
16
|
+
|
17
|
+
def self.windows?
|
18
|
+
@windows ||= begin
|
19
|
+
if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
|
20
|
+
false
|
21
|
+
elsif ENV['OS'] == 'Windows_NT'
|
22
|
+
true
|
23
|
+
else
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# true for linux, os x, cygwin
|
31
|
+
def self.posix?
|
32
|
+
@posix ||=
|
33
|
+
begin
|
34
|
+
if OS.windows?
|
35
|
+
begin
|
36
|
+
begin
|
37
|
+
# what if we're on interix...
|
38
|
+
# untested, of course
|
39
|
+
Process.wait fork{}
|
40
|
+
true
|
41
|
+
rescue NotImplementedError, NoMethodError
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
else
|
46
|
+
# assume non windows is posix
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# true for linux, false for windows, os x, cygwin
|
54
|
+
def self.linux?
|
55
|
+
if (host_os =~ /linux/)
|
56
|
+
true
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.iron_ruby?
|
63
|
+
@iron_ruby ||= begin
|
64
|
+
if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
|
65
|
+
true
|
66
|
+
else
|
67
|
+
false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.bits
|
73
|
+
@bits ||= begin
|
74
|
+
if host_cpu =~ /_64$/ || RUBY_PLATFORM =~ /x86_64/
|
75
|
+
64
|
76
|
+
elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#880613
|
77
|
+
ENV_JAVA['sun.arch.data.model'].to_i
|
78
|
+
elsif host_cpu == 'i386'
|
79
|
+
32
|
80
|
+
elsif host_os =~ /32$/ # mingw32, mswin32
|
81
|
+
32
|
82
|
+
else # cygwin only...I think
|
83
|
+
if 1.size == 8
|
84
|
+
64
|
85
|
+
else
|
86
|
+
32
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def self.java?
|
94
|
+
@java ||= begin
|
95
|
+
if RUBY_PLATFORM =~ /java/
|
96
|
+
true
|
97
|
+
else
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.ruby_bin
|
104
|
+
@ruby_exe ||= begin
|
105
|
+
File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.mac?
|
110
|
+
@mac = begin
|
111
|
+
if host_os =~ /darwin/
|
112
|
+
true
|
113
|
+
else
|
114
|
+
false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.osx?
|
120
|
+
mac?
|
121
|
+
end
|
122
|
+
|
123
|
+
# amount of memory the current process "is using", in RAM
|
124
|
+
# (doesn't include any swap memory that it may be using, just that in actual RAM)
|
125
|
+
# raises 'unknown' on jruby currently
|
126
|
+
def self.rss_bytes
|
127
|
+
# attempt to do this in a jruby friendly way
|
128
|
+
if OS::Underlying.windows?
|
129
|
+
# MRI, Java, IronRuby, Cygwin
|
130
|
+
if OS.java?
|
131
|
+
# no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P
|
132
|
+
require 'java'
|
133
|
+
mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean
|
134
|
+
mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
|
135
|
+
else
|
136
|
+
wmi = nil
|
137
|
+
begin
|
138
|
+
require 'win32ole'
|
139
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
140
|
+
rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]
|
141
|
+
raise 'rss unknown for this platform ' + e.to_s
|
142
|
+
end
|
143
|
+
processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
|
144
|
+
memory_used = nil
|
145
|
+
# only allow for one...
|
146
|
+
for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
|
147
|
+
memory_used
|
148
|
+
end
|
149
|
+
elsif OS.posix? # linux [though I've heard it works in OS X]
|
150
|
+
kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
|
151
|
+
else
|
152
|
+
raise 'unknown rss for this platform'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Underlying
|
157
|
+
|
158
|
+
def self.bsd?
|
159
|
+
OS.osx?
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.windows?
|
163
|
+
ENV['OS'] == 'Windows_NT'
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.linux?
|
167
|
+
OS.host_os =~ /linux/ ? true : false
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.cygwin?
|
173
|
+
@cygwin = begin
|
174
|
+
if RUBY_PLATFORM =~ /-cygwin/
|
175
|
+
true
|
176
|
+
else
|
177
|
+
false
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.dev_null
|
183
|
+
@dev_null ||= begin
|
184
|
+
if OS.windows?
|
185
|
+
"NUL"
|
186
|
+
else
|
187
|
+
"/dev/null"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# provides easy way to see the relevant config entries
|
193
|
+
def self.report
|
194
|
+
relevant_keys = [
|
195
|
+
'arch',
|
196
|
+
'host',
|
197
|
+
'host_cpu',
|
198
|
+
'host_os',
|
199
|
+
'host_vendor',
|
200
|
+
'target',
|
201
|
+
'target_cpu',
|
202
|
+
'target_os',
|
203
|
+
'target_vendor',
|
204
|
+
]
|
205
|
+
RbConfig::CONFIG.reject {|key, val| !relevant_keys.include? key }.merge({'RUBY_PLATFORM' => RUBY_PLATFORM}).to_yaml
|
206
|
+
end
|
207
|
+
|
208
|
+
class << self
|
209
|
+
alias :doze? :windows? # a joke name but I use it and like it :P
|
210
|
+
alias :jruby? :java?
|
211
|
+
|
212
|
+
# delegators for relevant config values
|
213
|
+
%w(host host_cpu host_os).each do |method_name|
|
214
|
+
define_method(method_name) { config[method_name] }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
data/os.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{os}
|
8
|
+
s.version = "0.8.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["rdp", "David McCullars"]
|
12
|
+
s.date = %q{2011-05-19}
|
13
|
+
s.description = %q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
|
14
|
+
s.email = %q{rogerpack2005@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".autotest",
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"autotest/discover.rb",
|
28
|
+
"lib/os.rb",
|
29
|
+
"os.gemspec",
|
30
|
+
"spec/linux_spec.rb",
|
31
|
+
"spec/os_spec.rb",
|
32
|
+
"spec/osx_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/rdp/os}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/linux_spec.rb",
|
42
|
+
"spec/osx_spec.rb",
|
43
|
+
"spec/os_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 2.0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, [">= 2.0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/spec/linux_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane to avoid sane being able to requir the gemified version...
|
4
|
+
require 'rspec' # rspec2
|
5
|
+
|
6
|
+
describe 'For Linux, (Ubuntu, Ubuntu 10.04 LTS) ' do
|
7
|
+
before(:each) do
|
8
|
+
ENV.should_receive(:[]).with('OS').any_number_of_times.and_return()
|
9
|
+
## Having difficulties finding a stub for RUBY_PLATFORM
|
10
|
+
# Looking into something like: http://stackoverflow.com/questions/1698335/can-i-use-rspec-mocks-to-stub-out-version-constants
|
11
|
+
# For now, simply using RbConfig::CONFIG
|
12
|
+
# Kernel.stub!(:const_get).with('RUBY_PLATFORM').and_return("i686-linux")
|
13
|
+
RbConfig::CONFIG.stub!(:[]).with('host_os').and_return('linux_gnu')
|
14
|
+
RbConfig::CONFIG.stub!(:[]).with('host_cpu').and_return('i686')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe OS do
|
18
|
+
subject { OS } # class, not instance
|
19
|
+
|
20
|
+
it { should be_linux }
|
21
|
+
it { should be_posix }
|
22
|
+
|
23
|
+
it { should_not be_mac }
|
24
|
+
it { should_not be_osx }
|
25
|
+
it { should_not be_windows }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe OS::Underlying do
|
30
|
+
subject { OS::Underlying } # class, not instance
|
31
|
+
|
32
|
+
it { should be_linux }
|
33
|
+
|
34
|
+
it { should_not be_bsd }
|
35
|
+
it { should_not be_windows }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -1,122 +1,145 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
assert OS.windows? ==
|
14
|
-
assert OS.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
1
|
+
require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe "OS" do
|
4
|
+
|
5
|
+
it "identifies whether windows? or posix?" do
|
6
|
+
if ENV['OS'] == 'Windows_NT'
|
7
|
+
unless RUBY_PLATFORM =~ /cygwin/
|
8
|
+
assert OS.windows? == true
|
9
|
+
assert OS.doze? == true
|
10
|
+
assert OS.posix? == false
|
11
|
+
else
|
12
|
+
assert OS::Underlying.windows?
|
13
|
+
assert OS.windows? == false
|
14
|
+
assert OS.posix? == true
|
15
|
+
end
|
16
|
+
assert OS::Underlying.windows?
|
17
|
+
elsif [/linux/, /darwin/].any? {|posix_pattern| (RbConfig::CONFIG["host_os"] =~ posix_pattern) || RUBY_PLATFORM =~ posix_pattern }
|
18
|
+
assert OS.windows? == false
|
19
|
+
assert OS.posix? == true
|
20
|
+
assert !OS::Underlying.windows?
|
21
|
+
else
|
22
|
+
pending "create test"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a bits method" do
|
27
|
+
if RUBY_PLATFORM =~ /mingw32/
|
28
|
+
assert OS.bits == 32
|
29
|
+
elsif RUBY_PLATFORM =~ /64/ # linux...
|
30
|
+
assert OS.bits == 64
|
31
|
+
elsif RUBY_PLATFORM =~ /i686/
|
32
|
+
assert OS.bits == 32
|
33
|
+
elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_os'] =~ /32$/
|
34
|
+
assert OS.bits == 32
|
35
|
+
elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_cpu'] =~ /i386/
|
36
|
+
assert OS.bits == 32
|
37
|
+
elsif RUBY_PLATFORM =~ /i386/
|
38
|
+
assert OS.bits == 32
|
39
|
+
else
|
40
|
+
pending "os bits not tested!" + RUBY_PLATFORM + ' ' + RbConfig::CONFIG['host_os']
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have an iron_ruby method" do
|
46
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
|
47
|
+
assert OS.iron_ruby? == true
|
48
|
+
else
|
49
|
+
assert OS.iron_ruby? == false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should know if you're on java" do
|
54
|
+
if RUBY_PLATFORM == 'java'
|
55
|
+
assert OS.java? == true # must be [true | false]
|
56
|
+
else
|
57
|
+
assert OS.java? == false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have a ruby_bin method" do
|
62
|
+
if OS.windows?
|
63
|
+
assert OS.ruby_bin.include?('.exe')
|
64
|
+
if OS.iron_ruby?
|
65
|
+
assert OS.ruby_bin.include?('ir.exe')
|
66
|
+
else
|
67
|
+
assert OS.ruby_bin.include?('ruby.exe')
|
68
|
+
end
|
69
|
+
else
|
70
|
+
assert OS.ruby_bin.include?('ruby') && OS.ruby_bin.include?('/')
|
71
|
+
end
|
72
|
+
|
73
|
+
if OS.java?
|
74
|
+
assert OS.ruby_bin.include?('jruby') # I think
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should have a cygwin? method" do
|
80
|
+
if RUBY_PLATFORM =~ /cygwin/
|
81
|
+
assert OS.cygwin? == true
|
82
|
+
else
|
83
|
+
assert OS.cygwin? == false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a functional mac? method" do
|
88
|
+
if RUBY_PLATFORM =~ /darwin/
|
89
|
+
assert OS.mac? == true
|
90
|
+
else
|
91
|
+
assert OS.mac? == false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should have a way to get rss_bytes on each platform" do
|
96
|
+
bytes = OS.rss_bytes
|
97
|
+
assert bytes > 0 # should always be true
|
98
|
+
assert bytes.is_a?(Numeric) # don't want strings from any platform...
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should tell you what the right /dev/null is" do
|
102
|
+
if OS.windows?
|
103
|
+
OS.dev_null.should == "NUL"
|
104
|
+
else
|
105
|
+
OS.dev_null.should == "/dev/null"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have a jruby method" do
|
110
|
+
if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /^(jruby|java)/
|
111
|
+
assert OS.jruby?
|
112
|
+
else
|
113
|
+
assert !OS.jruby?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
describe OS, "provides access to to underlying config values" do
|
120
|
+
|
121
|
+
describe "#config, supplys the CONFIG hash" do
|
122
|
+
subject { OS.config }
|
123
|
+
|
124
|
+
specify { subject.should be_a(Hash) }
|
125
|
+
|
126
|
+
it "should supply 'host_cpu'" do
|
127
|
+
subject['host_cpu'].should eq(RbConfig::CONFIG['host_cpu'])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should supply 'host_os'" do
|
131
|
+
subject['host_os'].should eq(RbConfig::CONFIG['host_os'])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "by providing a delegate method for relevant keys in RbConfig::CONFIG" do
|
136
|
+
%w(host host_cpu host_os).sort.each do |config_key|
|
137
|
+
it "should delegate '#{config_key}'" do
|
138
|
+
expected = "TEST #{config_key}"
|
139
|
+
RbConfig::CONFIG.should_receive(:[]).with(config_key).and_return(expected)
|
140
|
+
|
141
|
+
OS.send(config_key).should == expected
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/spec/osx_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'For OSX (Snow Leopard, 10.6),' do
|
4
|
+
before(:each) do
|
5
|
+
ENV.stub!(:[]).with('OS').and_return(nil)
|
6
|
+
# Issues stubbing RUBY_PLATFORM, using RbConfig instead.
|
7
|
+
# Kernel.stub!(:RUBY_PLATFORM => "x86_64-darwin10.6")
|
8
|
+
RbConfig::CONFIG.stub!(:[]).with('host_os').and_return("darwin10.6.0")
|
9
|
+
RbConfig::CONFIG.stub!(:[]).with('host_cpu').and_return('i386')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe OS do
|
13
|
+
subject { OS } # class, not instance
|
14
|
+
|
15
|
+
it { should be_mac }
|
16
|
+
it { should be_osx }
|
17
|
+
it { should be_posix }
|
18
|
+
|
19
|
+
it { should_not be_windows }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe OS::Underlying do
|
24
|
+
subject { OS::Underlying } # class, not instance
|
25
|
+
|
26
|
+
it { should be_bsd }
|
27
|
+
it { should_not be_windows }
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: os
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 63
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
|
-
|
9
|
-
|
13
|
+
- rdp
|
14
|
+
- David McCullars
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date: 2011-
|
19
|
+
date: 2011-05-19 00:00:00 -06:00
|
15
20
|
default_executable:
|
16
21
|
dependencies:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
none: false
|
33
|
-
requirements:
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: "0"
|
37
|
-
type: :development
|
38
|
-
version_requirements: *id002
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rspec
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: "2.0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
39
37
|
description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
|
40
38
|
email: rogerpack2005@gmail.com
|
41
39
|
executables: []
|
@@ -43,41 +41,59 @@ executables: []
|
|
43
41
|
extensions: []
|
44
42
|
|
45
43
|
extra_rdoc_files:
|
46
|
-
|
44
|
+
- README.rdoc
|
47
45
|
files:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
- .autotest
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- autotest/discover.rb
|
55
|
+
- lib/os.rb
|
56
|
+
- os.gemspec
|
57
|
+
- spec/linux_spec.rb
|
58
|
+
- spec/os_spec.rb
|
59
|
+
- spec/osx_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
54
61
|
has_rdoc: true
|
55
62
|
homepage: http://github.com/rdp/os
|
56
63
|
licenses: []
|
57
64
|
|
58
65
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
61
68
|
require_paths:
|
62
|
-
|
69
|
+
- lib
|
63
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
71
|
none: false
|
65
72
|
requirements:
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
69
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
80
|
none: false
|
71
81
|
requirements:
|
72
|
-
|
73
|
-
|
74
|
-
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
75
88
|
requirements: []
|
76
89
|
|
77
90
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.3.7
|
79
92
|
signing_key:
|
80
93
|
specification_version: 3
|
81
94
|
summary: Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.
|
82
95
|
test_files:
|
83
|
-
|
96
|
+
- spec/linux_spec.rb
|
97
|
+
- spec/osx_spec.rb
|
98
|
+
- spec/os_spec.rb
|
99
|
+
- spec/spec_helper.rb
|