sys-cpu 0.8.3 → 0.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c889d0a79359903abbe62cbd38095a88335386cc3c930b61ad94c9000350956
4
- data.tar.gz: b050390fc7fccbc4ad842f348e5dd702432f221c037a533bb4df2138d198d70c
3
+ metadata.gz: 465bd2540877db4c141949b95fb9c2d011497f532a9325d604da521ab98b878a
4
+ data.tar.gz: 27e1124d09070b074db611e9d392a32739f15554841ba0fe0b51c865414e592b
5
5
  SHA512:
6
- metadata.gz: 780e4ee7023069eb9c0d6dc0beb296edacda8db250f84cabada5961d2ab6728acd311a7eab41c292703feec6904a3caee6927b676454db46f4e6c1a248a06d12
7
- data.tar.gz: 310b45098badac319002989cd86009cb85fe4924300fb737f8de1b5c62fd2846f104c46a87233f2644dbc6527df1579cf5aa1eb78faea965eecd1648ddc46d15
6
+ metadata.gz: aece81104122383014b5e396a499550d3da21dadfb06846881786eb0898f2402452fe90a2f9c30a86ce89dbd6fad4bc16dfa9b0beafe3aa80cb8c120c3fbab05
7
+ data.tar.gz: 33e149e2e2ba7723609dc89ebb095f6df6496f7c2f4ef17656e2373fd004c88d51c3d75b3fec74dcaabcdd663289c00757771bd759869122c6935a4c3b972f75
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,10 @@
1
+ == 0.9.0 - 12-May-2020
2
+ * Added explicit freq, architecture, num_cpu and model methods to the Linux
3
+ version in an effort to create a common interface across platforms.
4
+ * Modified the Linux version so that method_missing will raise a NoMethodError
5
+ if you try to call access an attribute that doesn't exist.
6
+ * Some updates to the Linux tests.
7
+
1
8
  == 0.8.3 - 18-Mar-2020
2
9
  * Properly include a LICENSE file as per the Apache-2.0 license.
3
10
 
@@ -1,4 +1,5 @@
1
1
  * install.rb
2
+ * LICENSE
2
3
  * MANIFEST.rdoc
3
4
  * CHANGES.rdoc
4
5
  * Rakefile
@@ -5,7 +5,7 @@ require 'rbconfig'
5
5
  module Sys
6
6
  class CPU
7
7
  # The version of the sys-cpu gem.
8
- VERSION = '0.8.3'.freeze
8
+ VERSION = '0.9.0'.freeze
9
9
  end
10
10
  end
11
11
 
@@ -70,11 +70,43 @@ module Sys
70
70
  array unless block_given?
71
71
  end
72
72
 
73
+ # Return the total number of logical CPU on the system.
74
+ #
75
+ def self.num_cpu
76
+ CPU_ARRAY.size
77
+ end
78
+
79
+ # Return the architecture of the CPU.
80
+ #
81
+ def self.architecture
82
+ case CPU_ARRAY.first['cpu_family']
83
+ when '3'
84
+ "x86"
85
+ when '6'
86
+ "x86_64"
87
+ else
88
+ nil
89
+ end
90
+ end
91
+
92
+ # Returns a string indicating the CPU model.
93
+ #
94
+ def self.model
95
+ CPU_ARRAY.first['model_name']
96
+ end
97
+
98
+ # Returns an integer indicating the speed of the CPU.
99
+ #
100
+ def self.freq
101
+ CPU_ARRAY.first['cpu_mhz'].to_f.round
102
+ end
103
+
73
104
  private
74
105
 
75
106
  # Create singleton methods for each of the attributes.
76
107
  #
77
108
  def self.method_missing(id, arg=0)
109
+ raise NoMethodError, "'#{id}'" unless CPU_ARRAY[arg].has_key?(id.to_s)
78
110
  rv = CPU_ARRAY[arg][id.to_s]
79
111
  if rv.nil?
80
112
  id = id.to_s + "?"
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-cpu'
5
- spec.version = '0.8.3'
5
+ spec.version = '0.9.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.license = 'Apache-2.0'
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.metadata = {
26
26
  'homepage_uri' => 'https://github.com/djberg96/sys-cpu',
27
27
  'bug_tracker_uri' => 'https://github.com/djberg96/sys-cpu/issues',
28
- 'changelog_uri' => 'https://github.com/djberg96/sys-cpu/blob/ffi/CHANGES',
28
+ 'changelog_uri' => 'https://github.com/djberg96/sys-cpu/blob/ffi/CHANGES.rdoc',
29
29
  'documentation_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
30
30
  'source_code_uri' => 'https://github.com/djberg96/sys-cpu',
31
31
  'wiki_uri' => 'https://github.com/djberg96/sys-cpu/wiki'
@@ -7,25 +7,48 @@
7
7
  require 'sys/cpu'
8
8
  require 'test-unit'
9
9
  require 'test_sys_cpu_version'
10
- include Sys
11
10
 
12
11
  class TC_Sys_CPU_Linux < Test::Unit::TestCase
13
- def test_all_dynamic_methods
12
+ test "dynamic methods are defined as expected" do
14
13
  assert_nothing_raised{
15
- CPU.processors{ |cs|
14
+ Sys::CPU.processors{ |cs|
16
15
  cs.members.each{ |m| cs[m].to_s }
17
16
  }
18
17
  }
19
18
  end
20
19
 
21
- def test_load_avg
22
- assert_nothing_raised{ CPU.load_avg }
23
- assert_equal(3, CPU.load_avg.length)
20
+ test "load average works as expected" do
21
+ assert_nothing_raised{ Sys::CPU.load_avg }
22
+ assert_equal(3, Sys::CPU.load_avg.length)
24
23
  end
25
24
 
26
- def test_cpu_stats
27
- assert_nothing_raised{ CPU.cpu_stats }
28
- assert_kind_of(Hash, CPU.cpu_stats)
29
- assert_equal(true, CPU.cpu_stats['cpu0'].length >= 4)
25
+ test "cpu_stats works as expected" do
26
+ assert_nothing_raised{ Sys::CPU.cpu_stats }
27
+ assert_kind_of(Hash, Sys::CPU.cpu_stats)
28
+ assert_true(Sys::CPU.cpu_stats['cpu0'].length >= 4)
29
+ end
30
+
31
+ test "architecture works as expected" do
32
+ assert_nothing_raised{ Sys::CPU.architecture }
33
+ assert_kind_of(String, Sys::CPU.architecture)
34
+ end
35
+
36
+ test "model works as expected" do
37
+ assert_nothing_raised{ Sys::CPU.model }
38
+ assert_kind_of(String, Sys::CPU.model)
39
+ end
40
+
41
+ test "freq works as expected" do
42
+ assert_nothing_raised{ Sys::CPU.freq }
43
+ assert_kind_of(Numeric, Sys::CPU.freq)
44
+ end
45
+
46
+ test "num_cpu works as expected" do
47
+ assert_nothing_raised{ Sys::CPU.num_cpu }
48
+ assert_kind_of(Numeric, Sys::CPU.num_cpu)
49
+ end
50
+
51
+ test "bogus methods are not picked up by method_missing" do
52
+ assert_raise(NoMethodError){ Sys::CPU.bogus }
30
53
  end
31
54
  end
@@ -10,7 +10,7 @@ require 'test-unit'
10
10
 
11
11
  class TC_Sys_CPU_VERSION < Test::Unit::TestCase
12
12
  test "version number is set to the expected value" do
13
- assert_equal('0.8.3', Sys::CPU::VERSION)
13
+ assert_equal('0.9.0', Sys::CPU::VERSION)
14
14
  end
15
15
 
16
16
  test "version number is frozen" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-cpu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -87,59 +87,59 @@ email: djberg96@gmail.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files:
90
- - CHANGES.rdoc
91
- - MANIFEST.rdoc
92
90
  - README.rdoc
91
+ - MANIFEST.rdoc
92
+ - CHANGES.rdoc
93
93
  files:
94
- - install.rb
95
- - LICENSE
94
+ - README.rdoc
95
+ - examples
96
+ - examples/example_sys_cpu_sunos.rb
97
+ - examples/example_sys_cpu_windows.rb
98
+ - examples/example_sys_cpu_hpux.rb
99
+ - examples/example_sys_cpu_linux.rb
100
+ - examples/example_sys_cpu_bsd.rb
101
+ - sys-cpu.gemspec
102
+ - MANIFEST.rdoc
103
+ - certs
104
+ - certs/djberg96_pub.pem
96
105
  - test
97
- - test/test_sys_cpu.rb
98
- - test/test_sys_cpu_windows.rb
99
106
  - test/test_sys_cpu_bsd.rb
100
107
  - test/test_sys_cpu_version.rb
108
+ - test/test_sys_cpu.rb
109
+ - test/test_sys_cpu_windows.rb
101
110
  - test/test_sys_cpu_sunos.rb
102
111
  - test/test_sys_cpu_hpux.rb
103
112
  - test/test_sys_cpu_linux.rb
104
- - Rakefile
105
- - certs
106
- - certs/djberg96_pub.pem
107
- - examples
108
- - examples/example_sys_cpu_linux.rb
109
- - examples/example_sys_cpu_hpux.rb
110
- - examples/example_sys_cpu_sunos.rb
111
- - examples/example_sys_cpu_bsd.rb
112
- - examples/example_sys_cpu_windows.rb
113
- - sys-cpu.gemspec
113
+ - doc
114
+ - doc/linux.txt
115
+ - doc/windows.txt
116
+ - doc/sunos.txt
117
+ - doc/hpux.txt
118
+ - doc/bsd.txt
119
+ - install.rb
120
+ - LICENSE
114
121
  - lib
122
+ - lib/sys-cpu.rb
115
123
  - lib/sys
116
- - lib/sys/unix
117
- - lib/sys/unix/sys
118
- - lib/sys/unix/sys/cpu.rb
124
+ - lib/sys/cpu.rb
119
125
  - lib/sys/linux
120
126
  - lib/sys/linux/sys
121
127
  - lib/sys/linux/sys/cpu.rb
122
- - lib/sys/cpu.rb
128
+ - lib/sys/unix
129
+ - lib/sys/unix/sys
130
+ - lib/sys/unix/sys/cpu.rb
123
131
  - lib/sys/windows
124
132
  - lib/sys/windows/sys
125
133
  - lib/sys/windows/sys/cpu.rb
126
- - lib/sys-cpu.rb
134
+ - Rakefile
127
135
  - CHANGES.rdoc
128
- - doc
129
- - doc/linux.txt
130
- - doc/sunos.txt
131
- - doc/windows.txt
132
- - doc/bsd.txt
133
- - doc/hpux.txt
134
- - MANIFEST.rdoc
135
- - README.rdoc
136
136
  homepage: https://github.com/djberg96/sys-cpu
137
137
  licenses:
138
138
  - Apache-2.0
139
139
  metadata:
140
140
  homepage_uri: https://github.com/djberg96/sys-cpu
141
141
  bug_tracker_uri: https://github.com/djberg96/sys-cpu/issues
142
- changelog_uri: https://github.com/djberg96/sys-cpu/blob/ffi/CHANGES
142
+ changelog_uri: https://github.com/djberg96/sys-cpu/blob/ffi/CHANGES.rdoc
143
143
  documentation_uri: https://github.com/djberg96/sys-cpu/wiki
144
144
  source_code_uri: https://github.com/djberg96/sys-cpu
145
145
  wiki_uri: https://github.com/djberg96/sys-cpu/wiki
metadata.gz.sig CHANGED
Binary file