sysinfo 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGES.txt +6 -0
  2. data/lib/sysinfo.rb +18 -9
  3. data/sysinfo.gemspec +2 -2
  4. metadata +3 -9
@@ -1,11 +1,17 @@
1
1
  SYSINFO, CHANGES
2
2
 
3
+
4
+ #### 0.8.1 (2014-02-11) #############################
5
+
6
+ * CHANGE: Use Etc.getpwuid [jperville]
7
+
3
8
  #### 0.8.0 (2012-04-30) #############################
4
9
 
5
10
  * CHANGE: Removed #to_s
6
11
  * CHANGE: #platform now returns VM-OS-IMPL-ARCH
7
12
  * CHANGE: json is the default output format
8
13
 
14
+
9
15
  #### 0.7.2 (2010-02-12) #############################
10
16
 
11
17
  * CHANGE: Removed hanna dependency [Diego Elio 'Flameeyes' Pettenò]
@@ -1,6 +1,7 @@
1
1
  require 'socket'
2
2
  require 'storable'
3
3
  require 'time'
4
+ require 'tmpdir'
4
5
 
5
6
  # = SysInfo
6
7
  #
@@ -9,7 +10,7 @@ require 'time'
9
10
  # specifically lib/platform.rb.
10
11
  class SysInfo < Storable
11
12
  unless defined?(IMPLEMENTATIONS)
12
- VERSION = "0.8.0".freeze
13
+ VERSION = "0.8.1".freeze
13
14
  IMPLEMENTATIONS = [
14
15
 
15
16
  # These are for JRuby, System.getproperty('os.name').
@@ -78,7 +79,7 @@ class SysInfo < Storable
78
79
  @vm, @os, @impl, @arch = find_platform_info
79
80
  @hostname, @ipaddress_internal, @uptime = find_network_info
80
81
  @ruby = RUBY_VERSION.split('.').collect { |v| v.to_i }
81
- @user = ENV['USER']
82
+ @user = getpwattr(:name) || ENV['USER']
82
83
  require 'Win32API' if @os == :windows && @vm == :ruby
83
84
  end
84
85
 
@@ -178,25 +179,25 @@ class SysInfo < Storable
178
179
  (ENV['PATH'] || '').split(delim)
179
180
  end
180
181
 
181
- def tmpdir_ruby_unix; (ENV['TMPDIR'] || '/tmp'); end
182
- def tmpdir_ruby_windows; (ENV['TMPDIR'] || 'C:\\temp'); end
182
+ def tmpdir_ruby_unix; (Dir.tmpdir || '/tmp'); end
183
+ def tmpdir_ruby_windows; (Dir.tmpdir || 'C:\\temp'); end
183
184
  def tmpdir_java
184
185
  default = @impl == :windows ? 'C:\\temp' : '/tmp'
185
- (ENV['TMPDIR'] || default)
186
+ (Dir.tmpdir || default)
186
187
  end
187
188
 
188
- def shell_ruby_unix; (ENV['SHELL'] || 'bash').to_sym; end
189
+ def shell_ruby_unix; (ENV['SHELL'] || getpwattr(:shell) || 'bash').to_sym; end
189
190
  def shell_ruby_windows; :dos; end
190
191
  alias_method :shell_java_unix, :shell_ruby_unix
191
192
  alias_method :shell_java_windows, :shell_ruby_windows
192
193
 
193
- def home_ruby_unix; File.expand_path(ENV['HOME']); end
194
+ def home_ruby_unix; File.expand_path(getpwattr(:dir)); end
194
195
  def home_ruby_windows; File.expand_path(ENV['USERPROFILE']); end
195
196
  def home_java
196
197
  if @impl == :windows
197
198
  File.expand_path(ENV['USERPROFILE'])
198
199
  else
199
- File.expand_path(ENV['HOME'])
200
+ File.expand_path(getpwattr(:dir))
200
201
  end
201
202
  end
202
203
 
@@ -265,9 +266,17 @@ class SysInfo < Storable
265
266
  end
266
267
  ipaddr
267
268
  end
269
+
270
+ # Returns a named attribute of the user's /etc/password entry, or nil.
271
+ # As an example, `getpwdattr(:home)` will return the user's home directory
272
+ # without relying on ENV['HOME'] being present.
273
+ def getpwattr(pwattr)
274
+ passwd = Etc.getpwuid(Process::Sys.getuid) || {}
275
+ passwd[pwattr]
276
+ end
268
277
  end
269
278
 
270
279
 
271
280
  if $0 == __FILE__
272
281
  puts SysInfo.new.dump('json')
273
- end
282
+ end
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "sysinfo"
3
3
  s.rubyforge_project = "sysinfo"
4
- s.version = "0.8.0"
4
+ s.version = "0.8.1"
5
5
  s.summary = "SysInfo: All your system-independent infoz in one handy class. "
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -41,4 +41,4 @@
41
41
  s.require_paths = %w[lib]
42
42
  s.rubygems_version = '1.3.0'
43
43
 
44
- end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sysinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-30 00:00:00.000000000 Z
12
+ date: 2014-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: storable
@@ -76,21 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
- segments:
80
- - 0
81
- hash: 1706058782098846642
82
79
  required_rubygems_version: !ruby/object:Gem::Requirement
83
80
  none: false
84
81
  requirements:
85
82
  - - ! '>='
86
83
  - !ruby/object:Gem::Version
87
84
  version: '0'
88
- segments:
89
- - 0
90
- hash: 1706058782098846642
91
85
  requirements: []
92
86
  rubyforge_project: sysinfo
93
- rubygems_version: 1.8.22
87
+ rubygems_version: 1.8.23
94
88
  signing_key:
95
89
  specification_version: 3
96
90
  summary: ! 'SysInfo: All your system-independent infoz in one handy class.'