sys-uptime 0.7.2-universal-mingw32 → 0.7.6-universal-mingw32

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: 1a2dd1832bebec9fd06b9481d0aeb067a2155e9b09c746814bb49bf4196e24d1
4
- data.tar.gz: 33b1ddb693e56b58f864e9fe63b84f4c7db5ee7030463c0ba2c6f3bec0652d80
3
+ metadata.gz: 9247a0eb3e35003f1c6b6e071300ed2e7f0cdef474fc4a8ed825987007ff17d0
4
+ data.tar.gz: f4f2d7015290c9dbfc753ba34e42ccd55554b452da6f2ecb3b164923c1864b4b
5
5
  SHA512:
6
- metadata.gz: 9e9a4994e293334e196804185fafd90ea1ea0a3ddfadf22e06942f04468bd59f11da60b89c10f414655ef4225b623259bbc13064218a687498976d3f270c5ae5
7
- data.tar.gz: 329787a710fde14f5d9e5ca40afd503b579e8225a26681f15b6a8d3f36f8d6d73b03ce993c95c6c09afeb5da3f5e463daf4aff47f6466b2bf15e9e97f69205b0
6
+ metadata.gz: 70f96bb5f84578d3c270441180f28f188bd47db77a3a44ff364a7d94a56cd27ae8f79bbe60a65f3b4d3a04c464805f541d890d9e052fe49ae50ca8a576aa7750
7
+ data.tar.gz: 36f44196608a3940162263c88bfd9ca6e8542be152492cc51eed5d5669e2c2a0d0870de4309229ec29bac674705656d21f6a9f4c6509efc2cd7efade6506e9f8
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,45 +1,68 @@
1
- == 0.7.2 - 4-Nov-2018
1
+ ## 0.7.6 - 9-Apr-2023
2
+ * Constructor is now officially private, as are several constants that were
3
+ never meant to be public.
4
+ * Lots of rubocop suggested updates.
5
+ * Minor refactoring for Windows.
6
+ * Minor updates, including Rakefile and gemspec metadata.
7
+
8
+ ## 0.7.5 - 29-Oct-2020
9
+ * Switched docs to markdown format.
10
+ * Added a Gemfile.
11
+
12
+ ## 0.7.4 - 18-Mar-2020
13
+ * Added a LICENSE file as per the requirements of the Apache-2.0 license.
14
+
15
+ ## 0.7.3 - 31-Dec-2019
16
+ * Attempting to call Sys::Uptime.new will now raise an error. I thought
17
+ this was already the case, but apparently one of the tests was bad.
18
+ * Added explicit .rdoc extensions to various text files so that github
19
+ will display them nicely.
20
+ * Switched from test-unit to rspec as the testing framework of choice.
21
+ * Updated the gemspec to reflect the filename updates, as well as the
22
+ added development dependency.
23
+
24
+ ## 0.7.2 - 4-Nov-2018
2
25
  * Added metadata to the gemspec.
3
26
  * The VERSION constant is now frozen.
4
27
  * Updated cert.
5
28
 
6
- == 0.7.1 - 14-May-2016
29
+ ## 0.7.1 - 14-May-2016
7
30
  * Altered internal layout, which also fixed a require bug. Thanks go
8
31
  to jkburges for the spot.
9
32
  * Moved the VERSION constant into a single file shared by all platforms.
10
33
 
11
- == 0.7.0 - 3-Oct-2015
34
+ ## 0.7.0 - 3-Oct-2015
12
35
  * Changed license to Apache 2.0.
13
36
  * Added a cert. This gem is now signed.
14
37
  * Added a sys-uptime.rb file for convenience.
15
38
  * Gem related tasks in the Rakefile now assume Rubygems 2.x.
16
39
 
17
- == 0.6.2 - 8-Nov-2014
40
+ ## 0.6.2 - 8-Nov-2014
18
41
  * Minor updates to gemspec and Rakefile.
19
42
 
20
- == 0.6.1 - 22-Oct-2012
43
+ ## 0.6.1 - 22-Oct-2012
21
44
  * Refactored a private method in the MS Windows source.
22
45
  * Minor fix for one private method test.
23
46
  * Fixed an RbConfig vs Config warning. Thanks Pedro Carrico.
24
47
 
25
- == 0.6.0 - 11-Dec-2011
48
+ ## 0.6.0 - 11-Dec-2011
26
49
  * Switched Unix code to use FFI.
27
50
  * Removed all of the C related tasks from the Rakefile and added the gem:build
28
51
  and gem:install tasks.
29
52
  * Internal directory layout changes, with appropriate changes to the gemspec.
30
53
 
31
- == 0.5.3 - 7-May-2009
54
+ ## 0.5.3 - 7-May-2009
32
55
  * Altered the Uptime.seconds implementation on Linux so that it works with
33
56
  both Ruby 1.8.x and 1.9.x. Thanks go to Alexey Chebotar for the spot.
34
57
 
35
- == 0.5.2 - 13-Dec-2008
58
+ ## 0.5.2 - 13-Dec-2008
36
59
  * Fixed a date/time issue in the Windows version caused by Ruby itself.
37
60
  * Fixed the Uptime.seconds, Uptime.minutes and Uptime.hours methods on MS
38
61
  Windows.
39
62
  * Renamed the test file to 'test_sys_uptime.rb'.
40
63
  * Some minor updates to the Rakefile.
41
64
 
42
- == 0.5.1 - 26-Jul-2007
65
+ ## 0.5.1 - 26-Jul-2007
43
66
  * Fixed bug in the MS Windows version caused by incorrect parsing of an
44
67
  MS specific date format (caused by a bug in Ruby 1.8.6). Thanks go to
45
68
  Robert H. for the spot.
@@ -48,7 +71,7 @@
48
71
  * Added an 'install_gem' Rake task, and updated the README installation
49
72
  instructions.
50
73
 
51
- == 0.5.0 - 30-Mar-2007
74
+ ## 0.5.0 - 30-Mar-2007
52
75
  * For platforms that use C code, the code now always uses the sysctl()
53
76
  function if supported by your system. This replaces the platform specific
54
77
  checks I was doing for the various BSD flavors.
@@ -58,20 +81,20 @@
58
81
  * Added a Rakefile - users should now use the 'test' and 'install' rake tasks.
59
82
  * Updates to the MANIFEST, README and uptime.txt files.
60
83
 
61
- == 0.4.5 - 19-Nov-2006
84
+ ## 0.4.5 - 19-Nov-2006
62
85
  * Internal layout changes, minor doc updates and gemspec improvements.
63
86
  * No code changes.
64
87
 
65
- == 0.4.4 - 30-Jun-2006
88
+ ## 0.4.4 - 30-Jun-2006
66
89
  * Added inline rdoc documentation to the source files.
67
90
  * Added a gemspec.
68
91
 
69
- == 0.4.3 - 18-Dec-2005
92
+ ## 0.4.3 - 18-Dec-2005
70
93
  * Changed the Linux version to pure Ruby. The current method of determining
71
94
  uptime in unix.c does not work in Linux kernel 2.6+. So, from now on it
72
95
  reads out of /proc/uptime.
73
96
 
74
- == 0.4.2 - 6-May-2005
97
+ ## 0.4.2 - 6-May-2005
75
98
  * Fixed a potential boot_time bug.
76
99
  * Removed the version.h file. It's no longer needed since the Windows
77
100
  version is pure Ruby.
@@ -83,13 +106,13 @@
83
106
  * Made most documents rdoc friendly.
84
107
  * Moved project to RubyForge.
85
108
 
86
- == 0.4.1 - 14-Dec-2004
109
+ ## 0.4.1 - 14-Dec-2004
87
110
  * Moved freebsd code into unix.c file.
88
111
  * Should now work past 249 days (2**31) on systems that have utmpx.h.
89
112
  * Fixed a bug with regards to boot_time, where it was possible that it would
90
113
  simply be empty.
91
114
 
92
- == 0.4.0 - 8-Jul-2004
115
+ ## 0.4.0 - 8-Jul-2004
93
116
  * Removed all reference to the CLK_TCK constant, as per documentation from
94
117
  Richard Stevens that it is deprecated and that sysconf() should be used
95
118
  instead (well, I knew about this, but ignored it until now).
@@ -109,18 +132,18 @@
109
132
  * Removed the uptime.html file - you may generate that on your own.
110
133
  * Added warranty and license info.
111
134
 
112
- == 0.3.2 - 30-Dec-2003
135
+ ## 0.3.2 - 30-Dec-2003
113
136
  * Cleaned up some warnings that showed up with -Wall on some unix platforms
114
137
  (int vs long format, explicit include)
115
138
  * Minor test suite and extconf.rb changes
116
139
 
117
- == 0.3.1 - 25-Jun-2003
140
+ ## 0.3.1 - 25-Jun-2003
118
141
  * Modified test files to handle HP-UX extensions
119
142
  * Minor doc updates
120
143
  * Added the dhms() method. Actually, this was in the 0.3.0
121
144
  release, I just forgot to mention it in this file :)
122
145
 
123
- == 0.3.0 - 22-Jun-2003
146
+ ## 0.3.0 - 22-Jun-2003
124
147
  * Added OS X support - thanks go to Mike Hall for the patch
125
148
  * Fixed incorrect values in FreeBSD (again Mike Hall)
126
149
  * Modified tc_unix.rb test suite to handle OS X, along with a bit
@@ -129,7 +152,7 @@
129
152
  * Separated FreeBSD/OS X source into its own file (freebsd.c).
130
153
  The #ifdefs were starting to get too ugly for me
131
154
 
132
- == 0.2.1 - 13-May-2003
155
+ ## 0.2.1 - 13-May-2003
133
156
  * Fixed bug in extconf.rb file, and made some major changes
134
157
  * Modified test.rb for those without TestUnit
135
158
  * Modified TestUnit tests - some bogus tests were removed
@@ -139,7 +162,7 @@
139
162
  * Docs automatically included in doc directory (i.e. no more interactive
140
163
  document creation)
141
164
 
142
- == 0.2.0 - 13-Mar-2003
165
+ ## 0.2.0 - 13-Mar-2003
143
166
  * Added MS Windows support
144
167
  * Added a VERSION constant
145
168
  * Added a test suite (for those with TestUnit installed)
@@ -148,7 +171,7 @@
148
171
  * Changelog and Manifest are now CHANGES and MANIFEST, respectively
149
172
  * Many changes to extconf.rb
150
173
 
151
- == 0.1.3 - 6-Jan-2003
174
+ ## 0.1.3 - 6-Jan-2003
152
175
  * Added a VERSION class method
153
176
  * Added a copyright notice
154
177
  * Fixed up the docs a bit and moved them to the doc directory
@@ -156,14 +179,14 @@
156
179
  * Modified test.rb script to make it better
157
180
  * Changed install instructions slightly
158
181
 
159
- == 0.1.2 - 25-Aug-2002
182
+ ## 0.1.2 - 25-Aug-2002
160
183
  * Slight change to preprocessor commands to avoid redefining CLK_TCK on
161
184
  those systems that define it in time.h
162
185
  * Added an INSTALL file
163
186
 
164
- == 0.1.1 - 21-Jun-2002
187
+ ## 0.1.1 - 21-Jun-2002
165
188
  * The CLK_TCK constant wasn't necessarily being set correctly, which could
166
189
  lead to some odd results. This has been fixed.
167
190
 
168
- == 0.1.0 - 17-Jun-2002
191
+ ## 0.1.0 - 17-Jun-2002
169
192
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -1,11 +1,12 @@
1
- * CHANGES
2
- * MANIFEST
1
+ * CHANGES.rdoc
2
+ * LICENSE
3
+ * MANIFEST.rdoc
3
4
  * Rakefile
4
- * README
5
+ * README.rdoc
5
6
  * sys-uptime.gemspec
6
7
  * certs/djberg96_pub.pem
7
8
  * examples/test.rb
8
9
  * lib/sys-uptime.rb
9
10
  * lib/unix/sys/uptime.rb
10
11
  * lib/windows/sys/uptime.rb
11
- * test/test_sys_uptime.rb
12
+ * spec/sys_uptime_spec.rb
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ [![Ruby](https://github.com/djberg96/sys-uptime/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/sys-uptime/actions/workflows/ruby.yml)
2
+
3
+ ## Description
4
+ A Ruby interface for getting system uptime information.
5
+
6
+ ## Prerequisites
7
+ ffi 0.1.0 or later on Unixy platforms.
8
+
9
+ ## Installation
10
+
11
+ `gem install sys-uptime`
12
+
13
+ ## Synopsis
14
+ ```ruby
15
+ require 'sys-uptime'
16
+ include Sys
17
+
18
+ # Get everything
19
+ p Uptime.uptime
20
+ p Uptime.dhms.join(', ')
21
+
22
+ # Get individual units
23
+ p Uptime.days
24
+ p Uptime.hours
25
+ p Uptime.minutes
26
+ p Uptime.seconds
27
+
28
+ # Get the boot time
29
+ p Uptime.boot_time
30
+ ```
31
+
32
+ ## Notes
33
+ On MS Windows the +Uptime.uptime+ and +Uptime.boot_time+ methods optionally
34
+ takes a host name as a single argument. The default is localhost.
35
+
36
+ The current time, users and load average are not included in this library
37
+ module, even though you may be used to seeing them with the command
38
+ line version of +uptime+.
39
+
40
+ ## Known Bugs
41
+ None that I am aware of. Please log any bugs you find on the project
42
+ website at https://github.com/djberg96/sys-uptime.
43
+
44
+ ## Questions
45
+ "Doesn't Struct::Tms do this?" - No.
46
+
47
+ ## License
48
+ Apache-2.0
49
+
50
+ ## Copyright
51
+ Copyright 2002-2023, Daniel J. Berger
52
+
53
+ All Rights Reserved. This module is free software. It may be used,
54
+ redistributed and/or modified under the same terms as Ruby itself.
55
+
56
+ ## Warranty
57
+ This library is provided "as is" and without any express or
58
+ implied warranties, including, without limitation, the implied
59
+ warranties of merchantability and fitness for a particular purpose.
60
+
61
+ ## Acknowledgements
62
+ Andrea Fazzi for help with the FFI version.
63
+
64
+ Mike Hall for help with the BSD side of things for the original C code.
65
+
66
+ Ola Eriksson, whose source code I shamelessly plagiarized to get a better
67
+ implementation for systems that have the utmpx.h header file for the
68
+ original C code.
69
+
70
+ ## Author
71
+ Daniel J. Berger
data/Rakefile CHANGED
@@ -1,23 +1,18 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
4
6
 
5
- CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc")
7
+ CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "**/*.lock")
6
8
 
7
9
  namespace 'gem' do
8
10
  desc 'Build the sys-uptime gem'
9
11
  task :create => [:clean] do
10
12
  require 'rubygems/package'
11
- spec = eval(IO.read('sys-uptime.gemspec'))
13
+ spec = Gem::Specification.load('sys-uptime.gemspec')
12
14
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
-
14
- if File::ALT_SEPARATOR
15
- spec.platform = Gem::Platform.new(['universal','mingw32'])
16
- else
17
- spec.add_dependency('ffi', '>= 1.0.0')
18
- end
19
-
20
- Gem::Package.build(spec, true)
15
+ Gem::Package.build(spec)
21
16
  end
22
17
 
23
18
  desc 'Install the sys-uptime gem'
@@ -27,16 +22,9 @@ namespace 'gem' do
27
22
  end
28
23
  end
29
24
 
30
- desc "Run the test suite"
31
- Rake::TestTask.new do |t|
32
- if File::ALT_SEPARATOR
33
- t.libs << 'lib/windows'
34
- else
35
- t.libs << 'lib/unix'
36
- end
25
+ RuboCop::RakeTask.new
37
26
 
38
- t.warning = true
39
- t.verbose = true
40
- end
27
+ desc "Run the test suite"
28
+ RSpec::Core::RakeTask.new(:spec)
41
29
 
42
- task :default => :test
30
+ task :default => :spec
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
 
3
5
  # The Sys module serves as a namespace only.
4
6
  module Sys
5
-
6
7
  # The Uptime class encapsulates various bits of information regarding your
7
8
  # system's uptime, including boot time.
8
9
  class Uptime
@@ -12,8 +13,6 @@ module Sys
12
13
  # Error typically raised in one of the Uptime methods should fail.
13
14
  class Error < StandardError; end
14
15
 
15
- private
16
-
17
16
  # Hit this issue on Linux, not sure why
18
17
  begin
19
18
  find_type(:clock_t)
@@ -26,10 +25,10 @@ module Sys
26
25
  attach_function :time, [:pointer], :time_t
27
26
  attach_function :times, [:pointer], :clock_t
28
27
 
29
- private_class_method :strerror, :sysconf, :time, :times
28
+ private_class_method :strerror, :sysconf, :time, :times, :new
30
29
 
31
30
  begin
32
- attach_function :sysctl, [:pointer, :uint, :pointer, :pointer, :pointer, :size_t], :int
31
+ attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int
33
32
  private_class_method :sysctl
34
33
  rescue FFI::NotFoundError
35
34
  attach_function :setutxent, [], :void
@@ -43,6 +42,11 @@ module Sys
43
42
  TICKS = 100 # Ticks per second (TODO: use sysconf)
44
43
  BOOT_TIME = 2 # Boot time
45
44
 
45
+ private_constant :CTL_KERN
46
+ private_constant :KERN_BOOTTIME
47
+ private_constant :TICKS
48
+ private_constant :BOOT_TIME
49
+
46
50
  class Tms < FFI::Struct
47
51
  layout(
48
52
  :tms_utime, :clock_t,
@@ -52,6 +56,8 @@ module Sys
52
56
  )
53
57
  end
54
58
 
59
+ private_constant :Tms
60
+
55
61
  class Timeval < FFI::Struct
56
62
  layout(
57
63
  :tv_sec, :long,
@@ -59,6 +65,8 @@ module Sys
59
65
  )
60
66
  end
61
67
 
68
+ private_constant :Timeval
69
+
62
70
  class ExitStatus < FFI::Struct
63
71
  layout(
64
72
  :e_termination, :short,
@@ -66,6 +74,8 @@ module Sys
66
74
  )
67
75
  end
68
76
 
77
+ private_constant :ExitStatus
78
+
69
79
  class Utmpx < FFI::Struct
70
80
  layout(
71
81
  :ut_user, [:char, 32],
@@ -81,7 +91,7 @@ module Sys
81
91
  )
82
92
  end
83
93
 
84
- public
94
+ private_constant :Utmpx
85
95
 
86
96
  # Returns a Time object indicating the time the system was last booted.
87
97
  #
@@ -91,14 +101,14 @@ module Sys
91
101
  #
92
102
  def self.boot_time
93
103
  if RbConfig::CONFIG['host_os'] =~ /linux/i
94
- Time.now - self.seconds
104
+ Time.now - seconds
95
105
  elsif respond_to?(:sysctl, true)
96
106
  tv = Timeval.new
97
107
  mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_KERN, KERN_BOOTTIME])
98
108
  size = FFI::MemoryPointer.new(:long, 1).write_int(tv.size)
99
109
 
100
110
  if sysctl(mib, 2, tv, size, nil, 0) != 0
101
- raise SystemCallError, 'sysctl() - ' + strerror(FFI.errno)
111
+ raise SystemCallError, "sysctl function failed: #{strerror(FFI.errno)}"
102
112
  end
103
113
 
104
114
  Time.at(tv[:tv_sec], tv[:tv_usec])
@@ -126,18 +136,20 @@ module Sys
126
136
  #
127
137
  def self.seconds
128
138
  if RbConfig::CONFIG['host_os'] =~ /linux/i
139
+ # rubocop:disable Lint/RescueException
129
140
  begin
130
- IO.read('/proc/uptime').split.first.to_i
141
+ File.read('/proc/uptime').split.first.to_i
131
142
  rescue Exception => err
132
143
  raise Error, err
133
144
  end
145
+ # rubocop:enable Lint/RescueException
134
146
  elsif respond_to?(:sysctl, true)
135
147
  tv = Timeval.new
136
148
  mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_KERN, KERN_BOOTTIME])
137
149
  size = FFI::MemoryPointer.new(:long, 1).write_int(tv.size)
138
150
 
139
151
  if sysctl(mib, 2, tv, size, nil, 0) != 0
140
- raise SystemCallError, 'sysctl() - ' + strerror(FFI.errno)
152
+ raise SystemCallError, "sysctl function failed: #{strerror(FFI.errno)}"
141
153
  end
142
154
 
143
155
  time(nil) - tv[:tv_sec]
@@ -187,11 +199,11 @@ module Sys
187
199
  def self.uptime
188
200
  secs = seconds
189
201
  days = secs / 86400
190
- secs -= days * 86400
202
+ secs -= days * 86400
191
203
  hours = secs / 3600
192
- secs -= hours * 3600
193
- mins = secs / 60
194
- secs -= mins * 60
204
+ secs -= hours * 3600
205
+ mins = secs / 60
206
+ secs -= mins * 60
195
207
 
196
208
  "#{days}:#{hours}:#{mins}:#{secs}"
197
209
  end
data/lib/sys/uptime.rb CHANGED
@@ -1,12 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if File::ALT_SEPARATOR
2
4
  require_relative 'windows/sys/uptime'
3
5
  else
4
6
  require_relative 'unix/sys/uptime'
5
7
  end
6
8
 
9
+ # The Sys module serves as a namespace only.
7
10
  module Sys
11
+ # The Uptime class serves as a base singleton class to hang uptime related methods on.
8
12
  class Uptime
9
13
  # The version of the sys-uptime library
10
- VERSION = '0.7.2'.freeze
14
+ VERSION = '0.7.6'
15
+
16
+ private_class_method :new
11
17
  end
12
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'win32ole'
2
4
  require 'socket'
3
5
  require 'date'
@@ -5,14 +7,15 @@ require 'time'
5
7
 
6
8
  # The Sys module serves as a namespace only.
7
9
  module Sys
8
-
9
10
  # The Uptime class encapsulates various bits of information regarding your
10
11
  # system's uptime, including boot time.
11
12
  class Uptime
12
-
13
13
  # Error typically raised in one of the Uptime methods should fail.
14
14
  class Error < StandardError; end
15
15
 
16
+ # You cannot instantiate an instance of Sys::Uptime.
17
+ private_class_method :new
18
+
16
19
  # Returns the boot time as a Time object.
17
20
  #
18
21
  # Example:
@@ -23,15 +26,12 @@ module Sys
23
26
  cs = "winmgmts://#{host}/root/cimv2"
24
27
  begin
25
28
  wmi = WIN32OLE.connect(cs)
26
- rescue WIN32OLERuntimeError => e
27
- raise Error, e
29
+ rescue WIN32OLERuntimeError => err
30
+ raise Error, err
28
31
  else
29
- query = "select LastBootupTime from Win32_OperatingSystem"
30
- results = wmi.ExecQuery(query)
31
- results.each{ |ole|
32
- time_array = parse_ms_date(ole.LastBootupTime)
33
- return Time.mktime(*time_array)
34
- }
32
+ query = 'select LastBootupTime from Win32_OperatingSystem'
33
+ result = wmi.ExecQuery(query).itemIndex(0).LastBootupTime
34
+ Time.parse(result.split('.').first)
35
35
  end
36
36
  end
37
37
 
@@ -78,7 +78,7 @@ module Sys
78
78
  #
79
79
  # Sys::Uptime.hours # => 33
80
80
  #
81
- def self.hours(host=Socket.gethostname)
81
+ def self.hours(host = Socket.gethostname)
82
82
  minutes(host) / 60
83
83
  end
84
84
 
@@ -89,7 +89,7 @@ module Sys
89
89
  #
90
90
  # Sys::Uptime.minutes # => 1980
91
91
  #
92
- def self.minutes(host=Socket.gethostname)
92
+ def self.minutes(host = Socket.gethostname)
93
93
  seconds(host) / 60
94
94
  end
95
95
 
@@ -100,7 +100,7 @@ module Sys
100
100
  #
101
101
  # Sys::Uptime.seconds # => 118800
102
102
  #
103
- def self.seconds(host=Socket.gethostname)
103
+ def self.seconds(host = Socket.gethostname)
104
104
  get_seconds(host)
105
105
  end
106
106
 
@@ -111,7 +111,7 @@ module Sys
111
111
  #
112
112
  def self.parse_ms_date(str)
113
113
  return if str.nil?
114
- return Time.parse(str.split('.').first)
114
+ Time.parse(str.split('.').first)
115
115
  end
116
116
 
117
117
  private_class_method :parse_ms_date
@@ -136,7 +136,7 @@ module Sys
136
136
  # Returns the number of seconds since boot.
137
137
  #
138
138
  def self.get_seconds(host)
139
- (Time.now - boot_time).to_i
139
+ (Time.now - boot_time(host)).to_i
140
140
  end
141
141
 
142
142
  private_class_method :get_seconds
data/lib/sys-uptime.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'sys/uptime'
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ #####################################################################
4
+ # sys_uptime_spec.rb
5
+ #
6
+ # Test suite for sys-uptime. This should generally be run via the
7
+ # 'rake test' task, since it handles the pre-setup code for you.
8
+ #####################################################################
9
+ require 'sys/uptime'
10
+ require 'rspec'
11
+ require 'socket'
12
+
13
+ RSpec.describe Sys::Uptime do
14
+ let(:plausible_seconds) { ENV['CI'] ? 30 : 120 }
15
+
16
+ example 'version is set to expected value' do
17
+ expect(Sys::Uptime::VERSION).to eql('0.7.6')
18
+ expect(Sys::Uptime::VERSION.frozen?).to be(true)
19
+ end
20
+
21
+ example 'constructor is private' do
22
+ expect{ described_class.new }.to raise_error(NoMethodError)
23
+ end
24
+
25
+ example 'seconds method basic functionality' do
26
+ expect(described_class).to respond_to(:seconds)
27
+ expect{ described_class.seconds }.not_to raise_error
28
+ end
29
+
30
+ example 'seconds method returns a plausible value' do
31
+ expect(described_class.seconds).to be_a(Integer)
32
+ expect(described_class.seconds).to be > plausible_seconds
33
+ end
34
+
35
+ example 'minutes method basic functionality' do
36
+ expect(described_class).to respond_to(:minutes)
37
+ expect{ described_class.minutes }.not_to raise_error
38
+ end
39
+
40
+ example 'minutes method returns a plausible value', :unless => ENV.fetch('CI', nil) do
41
+ expect(described_class.minutes).to be_a(Integer)
42
+ expect(described_class.minutes).to be > 3
43
+ end
44
+
45
+ example 'hours method basic functionality' do
46
+ expect(described_class).to respond_to(:hours)
47
+ expect{ described_class.hours }.not_to raise_error
48
+ end
49
+
50
+ example 'hours method returns a plausible value' do
51
+ expect(described_class.hours).to be_a(Integer)
52
+ expect(described_class.hours).to be >= 0
53
+ end
54
+
55
+ example 'days method basic functionality' do
56
+ expect(described_class).to respond_to(:days)
57
+ expect{ described_class.days }.not_to raise_error
58
+ end
59
+
60
+ example 'days method returns a plausible value' do
61
+ expect(described_class.days).to be_a(Integer)
62
+ expect(described_class.days).to be >= 0
63
+ end
64
+
65
+ example 'uptime method basic functionality' do
66
+ expect(described_class).to respond_to(:uptime)
67
+ expect{ described_class.uptime }.not_to raise_error
68
+ end
69
+
70
+ example 'uptime method returns a non-empty string' do
71
+ expect(described_class.uptime).to be_a(String)
72
+ expect(described_class.uptime.empty?).to be(false)
73
+ end
74
+
75
+ example 'uptime method does not accept any arguments', :unless => File::ALT_SEPARATOR do
76
+ expect{ described_class.uptime(1) }.to raise_error(ArgumentError)
77
+ end
78
+
79
+ example 'uptime accepts a host name on Windows', :if => File::ALT_SEPARATOR do
80
+ expect{ described_class.uptime(Socket.gethostname) }.not_to raise_error
81
+ end
82
+
83
+ example 'dhms method basic functionality' do
84
+ expect(described_class).to respond_to(:dhms)
85
+ expect{ described_class.dhms }.not_to raise_error
86
+ expect(described_class.dhms).to be_a(Array)
87
+ end
88
+
89
+ example 'dhms method returns an array of four elements' do
90
+ expect(described_class.dhms).not_to be_empty
91
+ expect(described_class.dhms.length).to eq(4)
92
+ end
93
+
94
+ example 'boot_time method basic functionality' do
95
+ expect(described_class).to respond_to(:boot_time)
96
+ expect{ described_class.boot_time }.not_to raise_error
97
+ end
98
+
99
+ example 'boot_time method returns a Time object' do
100
+ expect(described_class.boot_time).to be_a(Time)
101
+ end
102
+
103
+ example 'Uptime class cannot be instantiated' do
104
+ expect{ described_class.new }.to raise_error(StandardError)
105
+ end
106
+
107
+ example 'Ensure that ffi functions are private' do
108
+ methods = described_class.methods(false).map(&:to_s)
109
+ expect(methods).not_to include('time', 'times')
110
+ end
111
+ end
data/sys-uptime.gemspec CHANGED
@@ -2,25 +2,36 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-uptime'
5
- spec.version = '0.7.2'
5
+ spec.version = '0.7.6'
6
6
  spec.author = 'Daniel J. Berger'
7
- spec.license = 'Apache 2.0'
7
+ spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'https://github.com/djberg96/sys-uptime'
10
10
  spec.summary = 'A Ruby interface for getting system uptime information.'
11
- spec.test_file = 'test/test_sys_uptime.rb'
11
+ spec.test_file = 'spec/sys_uptime_spec.rb'
12
12
  spec.files = Dir["**/*"].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
15
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
+ if File::ALT_SEPARATOR
16
+ spec.platform = Gem::Platform.new(['universal', 'mingw32'])
17
+ else
18
+ spec.add_dependency('ffi', '~> 1.1')
19
+ end
20
+
21
+ spec.add_development_dependency('rake')
22
+ spec.add_development_dependency('rspec', '~> 3.9')
23
+ spec.add_development_dependency('rubocop')
24
+ spec.add_development_dependency('rubocop-rspec')
16
25
 
17
26
  spec.metadata = {
18
- 'homepage_uri' => 'https://github.com/djberg96/sys-uptime',
19
- 'bug_tracker_uri' => 'https://github.com/djberg96/sys-uptime/issues',
20
- 'changelog_uri' => 'https://github.com/djberg96/sys-uptime/blob/ffi/CHANGES',
21
- 'documentation_uri' => 'https://github.com/djberg96/sys-uptime/wiki',
22
- 'source_code_uri' => 'https://github.com/djberg96/sys-uptime',
23
- 'wiki_uri' => 'https://github.com/djberg96/sys-uptime/wiki'
27
+ 'homepage_uri' => 'https://github.com/djberg96/sys-uptime',
28
+ 'bug_tracker_uri' => 'https://github.com/djberg96/sys-uptime/issues',
29
+ 'changelog_uri' => 'https://github.com/djberg96/sys-uptime/blob/main/CHANGES.md',
30
+ 'documentation_uri' => 'https://github.com/djberg96/sys-uptime/wiki',
31
+ 'source_code_uri' => 'https://github.com/djberg96/sys-uptime',
32
+ 'wiki_uri' => 'https://github.com/djberg96/sys-uptime/wiki',
33
+ 'rubygems_mfa_required' => 'true',
34
+ 'github_repo' => 'https://github.com/djberg96/sys-uptime'
24
35
  }
25
36
 
26
37
  spec.description = <<-EOF
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-uptime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.6
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,8 +35,64 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2018-11-04 00:00:00.000000000 Z
39
- dependencies: []
38
+ date: 2023-04-10 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.9'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.9'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rubocop-rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
40
96
  description: |2
41
97
  The sys-uptime library is a simple interface for gathering uptime
42
98
  information. You can retrieve data in seconds, minutes, days, hours,
@@ -44,43 +100,35 @@ description: |2
44
100
  email: djberg96@gmail.com
45
101
  executables: []
46
102
  extensions: []
47
- extra_rdoc_files:
48
- - CHANGES
49
- - README
50
- - MANIFEST
103
+ extra_rdoc_files: []
51
104
  files:
52
- - certs
105
+ - CHANGES.md
106
+ - Gemfile
107
+ - LICENSE
108
+ - MANIFEST.md
109
+ - README.md
110
+ - Rakefile
53
111
  - certs/djberg96_pub.pem
54
- - CHANGES
55
- - examples
56
112
  - examples/uptime_test.rb
57
- - lib
58
- - lib/sys
59
- - lib/sys/unix
60
- - lib/sys/unix/sys
113
+ - lib/sys-uptime.rb
61
114
  - lib/sys/unix/sys/uptime.rb
62
115
  - lib/sys/uptime.rb
63
- - lib/sys/windows
64
- - lib/sys/windows/sys
65
116
  - lib/sys/windows/sys/uptime.rb
66
- - lib/sys-uptime.rb
67
- - MANIFEST
68
- - Rakefile
69
- - README
117
+ - spec/sys_uptime_spec.rb
70
118
  - sys-uptime.gemspec
71
- - test
72
- - test/test_sys_uptime.rb
73
119
  homepage: https://github.com/djberg96/sys-uptime
74
120
  licenses:
75
- - Apache 2.0
121
+ - Apache-2.0
76
122
  metadata:
77
123
  homepage_uri: https://github.com/djberg96/sys-uptime
78
124
  bug_tracker_uri: https://github.com/djberg96/sys-uptime/issues
79
- changelog_uri: https://github.com/djberg96/sys-uptime/blob/ffi/CHANGES
125
+ changelog_uri: https://github.com/djberg96/sys-uptime/blob/main/CHANGES.md
80
126
  documentation_uri: https://github.com/djberg96/sys-uptime/wiki
81
127
  source_code_uri: https://github.com/djberg96/sys-uptime
82
128
  wiki_uri: https://github.com/djberg96/sys-uptime/wiki
83
- post_install_message:
129
+ rubygems_mfa_required: 'true'
130
+ github_repo: https://github.com/djberg96/sys-uptime
131
+ post_install_message:
84
132
  rdoc_options: []
85
133
  require_paths:
86
134
  - lib
@@ -95,10 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
143
  - !ruby/object:Gem::Version
96
144
  version: '0'
97
145
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.6
100
- signing_key:
146
+ rubygems_version: 3.2.19
147
+ signing_key:
101
148
  specification_version: 4
102
149
  summary: A Ruby interface for getting system uptime information.
103
150
  test_files:
104
- - test/test_sys_uptime.rb
151
+ - spec/sys_uptime_spec.rb
metadata.gz.sig CHANGED
Binary file
data/README DELETED
@@ -1,66 +0,0 @@
1
- = Description
2
- A Ruby interface for getting system uptime information.
3
-
4
- = Prerequisites
5
- ffi 0.1.0 or later on Unixy platforms.
6
-
7
- = Installation
8
- gem install sys-uptime
9
-
10
- = Synopsis
11
- require 'sys-uptime'
12
- include Sys
13
-
14
- # Get everything
15
- p Uptime.uptime
16
- p Uptime.dhms.join(', ')
17
-
18
- # Get individual units
19
- p Uptime.days
20
- p Uptime.hours
21
- p Uptime.minutes
22
- p Uptime.seconds
23
-
24
- # Get the boot time
25
- p Uptime.boot_time
26
-
27
- = Notes
28
- On MS Windows the Uptime.uptime and Uptime_boot_time methods optionally
29
- takes a host name as a single argument. The default is localhost.
30
-
31
- The current time, users and load average are not included in this library
32
- module, even though you may be used to seeing them with the command
33
- line version of 'uptime'.
34
-
35
- == Known Bugs
36
- None that I am aware of. Please log any bugs you find on the project
37
- website at https://github.com/djberg96/sys-uptime.
38
-
39
- == Questions
40
- "Doesn't Struct::Tms do this?" - No.
41
-
42
- == License
43
- Apache 2.0
44
-
45
- == Copyright
46
- Copyright 2002-2018, Daniel J. Berger
47
-
48
- All Rights Reserved. This module is free software. It may be used,
49
- redistributed and/or modified under the same terms as Ruby itself.
50
-
51
- == Warranty
52
- This library is provided "as is" and without any express or
53
- implied warranties, including, without limitation, the implied
54
- warranties of merchantability and fitness for a particular purpose.
55
-
56
- == Acknowledgements
57
- Andrea Fazzi for help with the FFI version.
58
-
59
- Mike Hall for help with the BSD side of things for the original C code.
60
-
61
- Ola Eriksson, whose source code I shamelessly plagiarized to get a better
62
- implementation for systems that have the utmpx.h header file for the
63
- original C code.
64
-
65
- == Author
66
- Daniel J. Berger
@@ -1,107 +0,0 @@
1
- #####################################################################
2
- # test_sys_uptime.rb
3
- #
4
- # Test suite for sys-uptime. This should generally be run via the
5
- # 'rake test' task, since it handles the pre-setup code for you.
6
- #####################################################################
7
- require 'sys/uptime'
8
- require 'test-unit'
9
- require 'socket'
10
- include Sys
11
-
12
- class TC_Sys_Uptime < Test::Unit::TestCase
13
- test "version is set to expected value" do
14
- assert_equal('0.7.2', Uptime::VERSION)
15
- assert_true(Uptime::VERSION.frozen?)
16
- end
17
-
18
- test "seconds method basic functionality" do
19
- assert_respond_to(Uptime, :seconds)
20
- assert_nothing_raised{ Uptime.seconds }
21
- end
22
-
23
- test "seconds method returns a plausible value" do
24
- assert_kind_of(Integer, Uptime.seconds)
25
- assert_true(Uptime.seconds > 300)
26
- end
27
-
28
- test "minutes method basic functionality" do
29
- assert_respond_to(Uptime, :minutes)
30
- assert_nothing_raised{ Uptime.minutes }
31
- end
32
-
33
- test "minutes method returns a plausible value" do
34
- assert_kind_of(Integer, Uptime.minutes)
35
- assert_true(Uptime.minutes > 5)
36
- end
37
-
38
- test "hours method basic functionality" do
39
- assert_respond_to(Uptime, :hours)
40
- assert_nothing_raised{ Uptime.hours }
41
- end
42
-
43
- test "hours method returns a plausible value" do
44
- assert_kind_of(Integer, Uptime.hours)
45
- assert_true(Uptime.hours > 0)
46
- end
47
-
48
- test "days method basic functionality" do
49
- assert_respond_to(Uptime, :days)
50
- assert_nothing_raised{ Uptime.days }
51
- end
52
-
53
- test "days method returns a plausible value" do
54
- assert_kind_of(Integer, Uptime.days)
55
- assert_true(Uptime.days >= 0)
56
- end
57
-
58
- test "uptime method basic functionality" do
59
- assert_respond_to(Uptime, :uptime)
60
- assert_nothing_raised{ Uptime.uptime }
61
- end
62
-
63
- test "uptime method returns a non-empty string" do
64
- assert_kind_of(String, Uptime.uptime)
65
- assert_false(Uptime.uptime.empty?)
66
- end
67
-
68
- test "uptime method does not accept any arguments" do
69
- omit_if(File::ALT_SEPARATOR)
70
- assert_raise(ArgumentError){ Uptime.uptime(1) }
71
- end
72
-
73
- test "uptime accepts a host name on Windows" do
74
- omit_unless(File::ALT_SEPARATOR, "MS Windows only")
75
- assert_nothing_raised{ Uptime.uptime(Socket.gethostname) }
76
- end
77
-
78
- test "dhms method basic functionality" do
79
- assert_respond_to(Uptime, :dhms)
80
- assert_nothing_raised{ Uptime.dhms }
81
- assert_kind_of(Array, Uptime.dhms)
82
- end
83
-
84
- test "dhms method returns an array of four elements" do
85
- assert_false(Uptime.dhms.empty?)
86
- assert_equal(4, Uptime.dhms.length)
87
- end
88
-
89
- test "boot_time method basic functionality" do
90
- assert_respond_to(Uptime, :boot_time)
91
- assert_nothing_raised{ Uptime.boot_time }
92
- end
93
-
94
- test "boot_time method returns a Time object" do
95
- assert_kind_of(Time, Uptime.boot_time)
96
- end
97
-
98
- test "Uptime class cannot be instantiated" do
99
- assert_kind_of(StandardError, Uptime::Error.new)
100
- end
101
-
102
- test "Ensure that ffi functions are private" do
103
- methods = Uptime.methods(false).map{ |e| e.to_s }
104
- assert_false(methods.include?('time'))
105
- assert_false(methods.include?('times'))
106
- end
107
- end