os 0.7.2 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/README.rdoc +14 -5
  2. data/Rakefile +8 -29
  3. data/VERSION +1 -1
  4. data/lib/os.rb +23 -11
  5. data/spec/spec.os.rb +24 -12
  6. metadata +45 -64
  7. data/.gitignore +0 -21
@@ -1,14 +1,14 @@
1
1
  The OS gem allows for some easy telling if you're on windows or not.
2
2
 
3
3
  require 'os'
4
- >> OS.windows?
5
- => true
4
+ >> OS.windows?
5
+ => true # also OS.doze?
6
6
 
7
7
  >> OS.bits
8
8
  => 32
9
9
 
10
10
  >> OS.java?
11
- => true
11
+ => true # if you're running in jruby also OS.jruby?
12
12
 
13
13
  >> OS.ruby_bin
14
14
  => "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
@@ -19,11 +19,20 @@ require 'os'
19
19
  >> OS.mac?
20
20
  => false
21
21
 
22
+ >> OS.java? # same as OS.jruby?
23
+ => true
24
+
25
+ >> OS.dev_null
26
+ => "NUL" # or "/dev/null" depending on which platform
27
+
28
+ >> OS.rss_bytes
29
+ => 12300033 # rss bytes this process is using currently, works in Linux/windows
30
+
22
31
  If there are any other features you'd like, let me know.
23
32
 
24
- github.com/rdp/os
33
+ github.com/rdp/os for feedback et al
25
34
 
26
- Related:
35
+ Related projects:
27
36
 
28
37
  rubygems:
29
38
  Gem::Platform.local
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
+
5
+ begin
6
+ # require 'psych'
7
+ rescue ::LoadError
8
+ end
9
+
4
10
  begin
5
11
  require 'jeweler'
6
12
  Jeweler::Tasks.new do |gem|
@@ -9,39 +15,12 @@ begin
9
15
  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
16
  gem.email = "rogerpack2005@gmail.com"
11
17
  gem.homepage = "http://github.com/rdp/os"
12
- gem.authors = ["rdp"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
18
+ gem.authors = ["rdp", "David McCullars"]
19
+ gem.add_development_dependency "rspec", ">= 2.0"
14
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
21
  gem.add_development_dependency "sane"
16
22
  # gem.add_development_dependency "fast_require"
17
23
  end
18
- Jeweler::GemcutterTasks.new
19
24
  rescue LoadError
20
25
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
26
  end
22
-
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_files = FileList['spec/**/*_spec.rb']
27
- end
28
-
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
34
-
35
- task :spec => :check_dependencies
36
-
37
- task :default => :spec
38
-
39
- require 'rake/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
-
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.title = "os #{version}"
45
- rdoc.rdoc_files.include('README*')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
47
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.4
data/lib/os.rb CHANGED
@@ -4,7 +4,8 @@
4
4
  class OS
5
5
 
6
6
  # true if on windows [and/or jruby]
7
- # false if on linux or cygwin
7
+ # false if on linux or cygwin on windows
8
+
8
9
  def self.windows?
9
10
  @windows ||= begin
10
11
  if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
@@ -41,10 +42,6 @@ class OS
41
42
 
42
43
  end
43
44
 
44
- class << self
45
- alias :doze? :windows? # a joke but I use it
46
- end
47
-
48
45
  def self.iron_ruby?
49
46
  @iron_ruby ||= begin
50
47
  if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
@@ -61,7 +58,7 @@ class OS
61
58
  host_cpu = RbConfig::CONFIG['host_cpu']
62
59
  if host_cpu =~ /_64$/ # x86_64
63
60
  64
64
- elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64" http://www.ruby-forum.com/topic/202173#880613
61
+ elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#880613
65
62
  ENV_JAVA['sun.arch.data.model'].to_i
66
63
  elsif host_cpu == 'i386'
67
64
  32
@@ -114,17 +111,17 @@ class OS
114
111
  if OS::Underlying.windows?
115
112
  # MRI, Java, IronRuby, Cygwin
116
113
  if OS.java?
117
- # no win32ole yet available...
114
+ # no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P
118
115
  require 'java'
119
- mem_bean = java.lang.management.ManagementFactory.memory_mxbean
116
+ mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean
120
117
  mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
121
118
  else
122
119
  wmi = nil
123
120
  begin
124
121
  require 'win32ole'
125
122
  wmi = WIN32OLE.connect("winmgmts://")
126
- rescue LoadError, NoMethodError # NoMethod for IronRuby currently [sigh]
127
- raise 'rss unknown for this platform'
123
+ rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]
124
+ raise 'rss unknown for this platform ' + e.to_s
128
125
  end
129
126
  processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
130
127
  memory_used = nil
@@ -132,7 +129,7 @@ class OS
132
129
  for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
133
130
  memory_used
134
131
  end
135
- elsif OS.posix? # assume linux I guess...
132
+ elsif OS.posix? # linux [though I've heard it works in OS X]
136
133
  kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
137
134
  else
138
135
  raise 'unknown rss for this platform'
@@ -156,5 +153,20 @@ class OS
156
153
  end
157
154
  end
158
155
  end
156
+
157
+ def self.dev_null
158
+ @dev_null ||= begin
159
+ if OS.windows?
160
+ "NUL"
161
+ else
162
+ "/dev/null"
163
+ end
164
+ end
165
+ end
166
+
167
+ class << self
168
+ alias :doze? :windows? # a joke name but I use it and like it :P
169
+ alias :jruby? :java?
170
+ end
159
171
 
160
172
  end
@@ -1,10 +1,9 @@
1
- require 'rubygems' if RUBY_VERSION < '1.9'
2
- #require 'fast_require'
3
- require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane
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
4
  require 'sane'
5
- load File.dirname(__FILE__) + '/../lib/os.rb'
6
- require 'spec/autorun'
7
- require 'rbconfig'
5
+ load File.dirname(__FILE__) + '/../lib/os.rb' # just in case
6
+ require 'rspec' # rspec2
8
7
 
9
8
  describe "OS" do
10
9
 
@@ -90,7 +89,7 @@ describe "OS" do
90
89
  end
91
90
  end
92
91
 
93
- it "should have a mac? method" do
92
+ it "should have a functional mac? method" do
94
93
  if RUBY_PLATFORM =~ /darwin/
95
94
  assert OS.mac? == true
96
95
  else
@@ -99,12 +98,25 @@ describe "OS" do
99
98
  end
100
99
 
101
100
  it "should have a way to get rss_bytes on each platform" do
102
- if !OS.iron_ruby?
103
- bytes = OS.rss_bytes
104
- assert bytes > 0 # should always be true
105
- assert bytes.is_a?(Numeric) # don't want strings from any platform...
101
+ bytes = OS.rss_bytes
102
+ assert bytes > 0 # should always be true
103
+ assert bytes.is_a?(Numeric) # don't want strings from any platform...
104
+ end
105
+
106
+ it "should tell you what the right /dev/null is" do
107
+ if OS.windows?
108
+ OS.dev_null.should == "NUL"
109
+ else
110
+ OS.dev_null.should == "/dev/null"
111
+ end
112
+ end
113
+
114
+ it "should have a jruby method" do
115
+ if RUBY_DESCRIPTION =~ /^(jruby|java)/
116
+ assert OS.jruby?
117
+ else
118
+ assert !OS.jruby?
106
119
  end
107
120
  end
108
-
109
121
 
110
122
  end
metadata CHANGED
@@ -1,53 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: os
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 7
9
- - 2
10
- version: 0.7.2
4
+ prerelease:
5
+ version: 0.7.4
11
6
  platform: ruby
12
7
  authors:
13
- - rdp
8
+ - rdp
9
+ - David McCullars
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2010-05-18 00:00:00 -06:00
14
+ date: 2011-02-25 00:00:00 -07:00
19
15
  default_executable:
20
16
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
35
- type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: sane
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
49
- type: :development
50
- version_requirements: *id002
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "2.0"
26
+ type: :development
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: sane
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ type: :development
38
+ version_requirements: *id002
51
39
  description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
52
40
  email: rogerpack2005@gmail.com
53
41
  executables: []
@@ -55,48 +43,41 @@ executables: []
55
43
  extensions: []
56
44
 
57
45
  extra_rdoc_files:
58
- - README.rdoc
46
+ - README.rdoc
59
47
  files:
60
- - .document
61
- - .gitignore
62
- - README.rdoc
63
- - Rakefile
64
- - VERSION
65
- - lib/os.rb
66
- - spec/spec.os.rb
48
+ - .document
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/os.rb
53
+ - spec/spec.os.rb
67
54
  has_rdoc: true
68
55
  homepage: http://github.com/rdp/os
69
56
  licenses: []
70
57
 
71
58
  post_install_message:
72
- rdoc_options:
73
- - --charset=UTF-8
59
+ rdoc_options: []
60
+
74
61
  require_paths:
75
- - lib
62
+ - lib
76
63
  required_ruby_version: !ruby/object:Gem::Requirement
77
64
  none: false
78
65
  requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
85
69
  required_rubygems_version: !ruby/object:Gem::Requirement
86
70
  none: false
87
71
  requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
94
75
  requirements: []
95
76
 
96
77
  rubyforge_project:
97
- rubygems_version: 1.3.7
78
+ rubygems_version: 1.5.1
98
79
  signing_key:
99
80
  specification_version: 3
100
81
  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.
101
82
  test_files:
102
- - spec/spec.os.rb
83
+ - spec/spec.os.rb
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC