total 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/total.rb +4 -1
- data/lib/total/linux.rb +2 -1
- data/lib/total/osx.rb +7 -3
- data/test/total/test_linux.rb +7 -0
- data/test/total/test_osx.rb +7 -0
- data/total.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 298d4a200e57232fd0eeba31fe62700ca8d18e0d6a9cee8417f1446ab74cb08d
|
4
|
+
data.tar.gz: 77875dad56ad2430b08ba649cd22100ea74a459e0260e0071804803670cc4b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c572de46c7fb05c17e3accb9ad75cbfa7bb66aafbdeaf050aaaa81f8bb3f103be3f4a90cb8b9a201f2e8947b7adb475e6f751866195d5e198da17e90e8e5bd9b
|
7
|
+
data.tar.gz: df28c5fa8984abe8fc4e1cc824b49f4e1b9c72d80941892b473fe3565ed804327d0126c0f61d7b91454270bec019a746260864062bbc7bdfaaa2e27c0bef466a
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/yegor256/total.svg)](https://travis-ci.org/yegor256/total)
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/total.svg)](http://badge.fury.io/rb/total)
|
7
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/6e08ce63e597f241ccc7/maintainability)](https://codeclimate.com/github/yegor256/total/maintainability)
|
8
8
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/total/master/frames)
|
9
9
|
|
10
10
|
Total is a Ruby gem to detect the total amount of memory in the system.
|
data/lib/total.rb
CHANGED
@@ -37,6 +37,9 @@ require_relative 'total/osx'
|
|
37
37
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
38
38
|
# License:: MIT
|
39
39
|
module Total
|
40
|
+
# When it's impossible to detect something.
|
41
|
+
class CantDetect < StandardError; end
|
42
|
+
|
40
43
|
# Memory specifics.
|
41
44
|
class Mem
|
42
45
|
# Get it in bytes.
|
@@ -50,7 +53,7 @@ module Total
|
|
50
53
|
def target
|
51
54
|
return Total::OSX.new if RUBY_PLATFORM.include?('darwin')
|
52
55
|
return Total::Linux.new if RUBY_PLATFORM.include?('linux')
|
53
|
-
raise "Can\'t detect operating system: #{RUBY_PLATFORM}"
|
56
|
+
raise CantDetect, "Can\'t detect operating system: #{RUBY_PLATFORM}"
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
data/lib/total/linux.rb
CHANGED
@@ -32,10 +32,11 @@ module Total
|
|
32
32
|
class Linux
|
33
33
|
# Get the total in bytes
|
34
34
|
def memory
|
35
|
+
raise CantDetect unless File.exist?('/proc/meminfo')
|
35
36
|
IO.readlines('/proc/meminfo').each do |t|
|
36
37
|
return t.split(/ +/)[1].to_i * 1024 if t.start_with?('MemTotal:')
|
37
38
|
end
|
38
|
-
raise 'Can\'t detect memory size at /proc/meminfo'
|
39
|
+
raise CantDetect, 'Can\'t detect memory size at /proc/meminfo'
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/total/osx.rb
CHANGED
@@ -32,10 +32,14 @@ module Total
|
|
32
32
|
class OSX
|
33
33
|
# Get the total in bytes
|
34
34
|
def memory
|
35
|
-
|
36
|
-
|
35
|
+
begin
|
36
|
+
`sysctl -a`.split("\n").each do |t|
|
37
|
+
return t.split(' ')[1].to_i if t.start_with?('hw.memsize:')
|
38
|
+
end
|
39
|
+
rescue Errno::ENOENT => e
|
40
|
+
raise CantDetect, e.message
|
37
41
|
end
|
38
|
-
raise 'Can\'t detect memory size via sysctl'
|
42
|
+
raise CantDetect, 'Can\'t detect memory size via sysctl'
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
data/test/total/test_linux.rb
CHANGED
@@ -36,4 +36,11 @@ class LinuxTest < Minitest::Test
|
|
36
36
|
assert(!linux.memory.nil?)
|
37
37
|
assert(linux.memory > 1024 * 1024)
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_crashes_when_cant_detect
|
41
|
+
skip if RUBY_PLATFORM.include?('linux')
|
42
|
+
assert_raises Total::CantDetect do
|
43
|
+
Total::Linux.new.memory
|
44
|
+
end
|
45
|
+
end
|
39
46
|
end
|
data/test/total/test_osx.rb
CHANGED
@@ -36,4 +36,11 @@ class OSXTest < Minitest::Test
|
|
36
36
|
assert(!linux.memory.nil?)
|
37
37
|
assert(linux.memory > 1024 * 1024)
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_crashes_when_cant_detect
|
41
|
+
skip if RUBY_PLATFORM.include?('darwin')
|
42
|
+
assert_raises Total::CantDetect do
|
43
|
+
Total::OSX.new.memory
|
44
|
+
end
|
45
|
+
end
|
39
46
|
end
|
data/total.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.3.3'
|
32
32
|
s.required_ruby_version = '>=2.3'
|
33
33
|
s.name = 'total'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.2.0'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'Total memory calculator in Ruby'
|
37
37
|
s.description = 'Get total memory size of the system'
|