total 0.2.0 → 0.3.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: 298d4a200e57232fd0eeba31fe62700ca8d18e0d6a9cee8417f1446ab74cb08d
4
- data.tar.gz: 77875dad56ad2430b08ba649cd22100ea74a459e0260e0071804803670cc4b7c
3
+ metadata.gz: c2b318e9f39a42e339f249d53d84c9b804b2ac326080c1a553b90bb494ef83f7
4
+ data.tar.gz: edc9529d3e40c40e255bf9f804a69fc685b4edb317579980fc39a0020bc9ef35
5
5
  SHA512:
6
- metadata.gz: c572de46c7fb05c17e3accb9ad75cbfa7bb66aafbdeaf050aaaa81f8bb3f103be3f4a90cb8b9a201f2e8947b7adb475e6f751866195d5e198da17e90e8e5bd9b
7
- data.tar.gz: df28c5fa8984abe8fc4e1cc824b49f4e1b9c72d80941892b473fe3565ed804327d0126c0f61d7b91454270bec019a746260864062bbc7bdfaaa2e27c0bef466a
6
+ metadata.gz: 4482f27558e0e9a77ec815adc729e8659e7213632a4580c8fe3cf27ccdd876afbd43895ddc608b6e41a4ea05687dd53fa06409d16708995245468421a570ead5
7
+ data.tar.gz: 841d05c4dcb2aa8541542a608a48dbb51ada7096dc11b96b5cd6ade136d38d4e179e39a2cb980d5f1b9aa400eed5174c3c33e48fdf46e38203e1773c3917213e
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
- TargetRubyVersion: 2.3.3
3
+ TargetRubyVersion: 2.3
4
4
 
5
5
  Layout/EmptyLineAfterGuardClause:
6
6
  Enabled: false
data/Gemfile CHANGED
@@ -21,4 +21,5 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  source 'https://rubygems.org'
24
+ ruby '2.6.0'
24
25
  gemspec
data/README.md CHANGED
@@ -22,6 +22,27 @@ require 'total'
22
22
  puts Total::Mem.new.bytes
23
23
  ```
24
24
 
25
+ The following platforms are supported:
26
+
27
+ * MacOSX
28
+ * Linux
29
+ * FreeBSD
30
+ * <del>Windows</del> (help needed)
31
+
32
+ If the platform is not recognized or is not supported, `Total::CantDetect` exception
33
+ will be raised. You should catch it and proceed accordingly, for example:
34
+
35
+ ```ruby
36
+ def total_mb
37
+ Total::Mem.new.bytes / (1024 * 1024)
38
+ rescue Total::CantDetect
39
+ 512
40
+ end
41
+ ```
42
+
43
+ This code will return the actual memory size in Mb, if it can be detected,
44
+ or 512 otherwise.
45
+
25
46
  That's it.
26
47
 
27
48
  # How to contribute
@@ -23,6 +23,7 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require_relative 'total/linux'
26
+ require_relative 'total/freebsd'
26
27
  require_relative 'total/osx'
27
28
 
28
29
  # Total is a simple class to detect the total amount of memory in the system.
@@ -53,6 +54,7 @@ module Total
53
54
  def target
54
55
  return Total::OSX.new if RUBY_PLATFORM.include?('darwin')
55
56
  return Total::Linux.new if RUBY_PLATFORM.include?('linux')
57
+ return Total::FreeBSD.new if RUBY_PLATFORM.include?('freebsd')
56
58
  raise CantDetect, "Can\'t detect operating system: #{RUBY_PLATFORM}"
57
59
  end
58
60
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2018 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ # FreeBSD specific.
26
+ #
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
29
+ # License:: MIT
30
+ module Total
31
+ # FreeBSD specifics.
32
+ class FreeBSD
33
+ # Get the total in bytes
34
+ def memory
35
+ begin
36
+ `sysctl -a`.split("\n").each do |t|
37
+ return t.split(' ')[1].to_i if t.start_with?('hw.physmem:')
38
+ end
39
+ rescue Errno::ENOENT => e
40
+ raise CantDetect, e.message
41
+ end
42
+ raise CantDetect, 'Can\'t detect memory size via sysctl'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2018 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'minitest/autorun'
26
+ require_relative '../../lib/total/freebsd'
27
+
28
+ # FreeBSD test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
31
+ # License:: MIT
32
+ class FreeBSDTest < Minitest::Test
33
+ def test_fetch_memory_size
34
+ skip unless RUBY_PLATFORM.include?('freebsd')
35
+ freebsd = Total::FreeBSD.new
36
+ assert(!freebsd.memory.nil?)
37
+ assert(freebsd.memory > 1024 * 1024)
38
+ end
39
+
40
+ def test_crashes_when_cant_detect
41
+ skip if RUBY_PLATFORM.include?('freebsd')
42
+ assert_raises Total::CantDetect do
43
+ Total::FreeBSD.new.memory
44
+ end
45
+ end
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.2.0'
34
+ s.version = '0.3.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'
@@ -45,6 +45,6 @@ Gem::Specification.new do |s|
45
45
  s.add_development_dependency 'minitest', '5.11.3'
46
46
  s.add_development_dependency 'rake', '12.3.1'
47
47
  s.add_development_dependency 'rdoc', '4.3.0'
48
- s.add_development_dependency 'rubocop', '0.60.0'
49
- s.add_development_dependency 'rubocop-rspec', '1.30.1'
48
+ s.add_development_dependency 'rubocop', '0.62.0'
49
+ s.add_development_dependency 'rubocop-rspec', '1.31.0'
50
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: total
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-28 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.60.0
61
+ version: 0.62.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.60.0
68
+ version: 0.62.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.30.1
75
+ version: 1.31.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.30.1
82
+ version: 1.31.0
83
83
  description: Get total memory size of the system
84
84
  email: yegor256@gmail.com
85
85
  executables: []
@@ -97,9 +97,11 @@ files:
97
97
  - README.md
98
98
  - Rakefile
99
99
  - lib/total.rb
100
+ - lib/total/freebsd.rb
100
101
  - lib/total/linux.rb
101
102
  - lib/total/osx.rb
102
103
  - test/test_total.rb
104
+ - test/total/test_freebsd.rb
103
105
  - test/total/test_linux.rb
104
106
  - test/total/test_osx.rb
105
107
  - total.gemspec
@@ -123,12 +125,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6
128
+ rubygems_version: 3.0.1
128
129
  signing_key:
129
130
  specification_version: 2
130
131
  summary: Total memory calculator in Ruby
131
132
  test_files:
132
133
  - test/test_total.rb
134
+ - test/total/test_freebsd.rb
133
135
  - test/total/test_linux.rb
134
136
  - test/total/test_osx.rb