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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cdbfc5d8ebb43ace58469f0e7fb57770d1bfc3a284665ce0de834a2dccfdf63
4
- data.tar.gz: 7ea6c9a7d856eedf0636a23cb9001f87bc614dc3cd3e08e64d7e78ebffd2f51b
3
+ metadata.gz: 298d4a200e57232fd0eeba31fe62700ca8d18e0d6a9cee8417f1446ab74cb08d
4
+ data.tar.gz: 77875dad56ad2430b08ba649cd22100ea74a459e0260e0071804803670cc4b7c
5
5
  SHA512:
6
- metadata.gz: 5a9e423a957d3321a681cf8c992bd11b81ed77bb2ff5bb4692297515e25d74857aaf35afa0fe1acc1467b8e11ff848decc7b81e3c3408cd15743837dbb908baa
7
- data.tar.gz: c89699e9c027e1a6ca3bb0d6b3a89f680a7454e9e4ff784a623f8f7b1bb9fe81281576b6b01eb98739f6c5c23c846a6f3f463d29af0845ac59ddba94b002f9a6
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/5528e182bb5e4a2ecc1f/maintainability)](https://codeclimate.com/github/yegor256/total/maintainability)
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.
@@ -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
@@ -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
@@ -32,10 +32,14 @@ module Total
32
32
  class OSX
33
33
  # Get the total in bytes
34
34
  def memory
35
- `sysctl -a`.split("\n").each do |t|
36
- return t.split(' ')[1].to_i if t.start_with?('hw.memsize:')
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
@@ -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
@@ -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
@@ -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.1.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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: total
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko