vnstat-ruby 2.0.0 → 3.0.6

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
- SHA256:
3
- metadata.gz: 1147fd1dc7aa2c9d3990b48e410a1a2f68e8ecd3e5dfc390116131f703050624
4
- data.tar.gz: 5804a8055fc72e8f5dd9fefe888072524ebd8ee842fa26194b45130106dbc170
2
+ SHA1:
3
+ metadata.gz: 2214aef1d2fed1c199eb30e62fd0947193fb6f18
4
+ data.tar.gz: b5115aacbd68d2199faaec3bd2d7463ac10aaf97
5
5
  SHA512:
6
- metadata.gz: 9e2be0b328f5b8df0dea239b8c2554d812afc439c89798844fe80dc2edf4fb5f1841ffd1036c3470763fca10a2cc21d90a816043030e89bd250edf3151f3ccb6
7
- data.tar.gz: b163535f90d28910ec626e7d3e997c426addb363dfa50b242f5d0a384b0e9b92ceeeadc000a3d4a1d3af52934125b0ecaab6b6409b7b088448c0f810713f1861
6
+ metadata.gz: 33bc77a79debce5a520715e4676daea648f96cf5f2c8c2f977f1b2369dc2f85492bb19a7ddf6de88c00465cdc1f940fe8a082a24f5bdd756fbf8a070382a3947
7
+ data.tar.gz: 6fe044b316ac36c11654846e22c0fe94ac349f79eed7fd486461718632f00b42bdc1d1f3e292c1c024db82f246a51c6c94e1e8aeea28dbec41d01ad967d0d641
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -15,7 +15,7 @@ doc
15
15
  # jeweler generated
16
16
  pkg
17
17
 
18
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
19
  #
20
20
  # * Create a file at ~/.gitignore
21
21
  # * Include files you want ignored
@@ -47,3 +47,6 @@ pkg
47
47
 
48
48
  # For rubinius:
49
49
  #*.rbc
50
+
51
+ /.vscode
52
+ .DS_Store
@@ -7,11 +7,12 @@ AllCops:
7
7
  - '**/*.jbuilder'
8
8
  - Rakefile
9
9
  - spec/spec_helper.rb
10
+ TargetRubyVersion: '2.3'
10
11
 
11
12
  Metrics/BlockLength:
12
13
  Exclude:
13
14
  - 'spec/**/*.rb'
14
15
 
15
- Style/FileName:
16
+ Naming/FileName:
16
17
  Exclude:
17
- - Gemfile
18
+ - 'lib/vnstat-ruby.rb'
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.3.8
@@ -0,0 +1 @@
1
+ ruby 2.3.8
@@ -1,13 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - '2.1.10'
5
- - '2.2.8'
6
- - '2.3.6'
7
- - '2.4.3'
8
- - '2.5.0'
9
- before_install: gem install bundler -v 1.14.6
4
+ - '2.3.8'
5
+ - '2.4.5'
6
+ - '2.5.3'
7
+ - '2.6.1'
8
+ before_install: gem install bundler -v 2.0.2
10
9
  script: bundle exec rspec
11
- addons:
12
- code_climate:
13
- repo_token: 06a44082b0f5a5114eec226952c45443a4ac8c86e59e098869b5c07e420505ab
@@ -1,23 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vnstat-ruby (2.0.0)
5
- nokogiri (~> 1.8)
4
+ vnstat-ruby (3.0.6)
5
+ nokogiri (~> 1.10, >= 1.10.4)
6
+ systemcall (~> 1.0, >= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  ast (2.4.0)
12
+ coveralls (0.8.23)
13
+ json (>= 1.8, < 3)
14
+ simplecov (~> 0.16.1)
15
+ term-ansicolor (~> 1.3)
16
+ thor (>= 0.19.4, < 2.0)
17
+ tins (~> 1.6)
11
18
  diff-lcs (1.2.5)
12
- mini_portile2 (2.3.0)
13
- nokogiri (1.8.2)
14
- mini_portile2 (~> 2.3.0)
15
- parallel (1.12.1)
16
- parser (2.5.0.4)
19
+ docile (1.3.2)
20
+ jaro_winkler (1.5.2)
21
+ json (2.2.0)
22
+ mini_portile2 (2.4.0)
23
+ nokogiri (1.10.8)
24
+ mini_portile2 (~> 2.4.0)
25
+ parallel (1.17.0)
26
+ parser (2.6.3.0)
17
27
  ast (~> 2.4.0)
18
- powerpack (0.1.1)
19
28
  rainbow (3.0.0)
20
- rake (10.5.0)
29
+ rake (13.0.1)
21
30
  rspec (3.3.0)
22
31
  rspec-core (~> 3.3.0)
23
32
  rspec-expectations (~> 3.3.0)
@@ -31,27 +40,38 @@ GEM
31
40
  diff-lcs (>= 1.2.0, < 2.0)
32
41
  rspec-support (~> 3.3.0)
33
42
  rspec-support (3.3.0)
34
- rubocop (0.53.0)
43
+ rubocop (0.68.0)
44
+ jaro_winkler (~> 1.5.1)
35
45
  parallel (~> 1.10)
36
- parser (>= 2.5)
37
- powerpack (~> 0.1)
46
+ parser (>= 2.5, != 2.5.1.1)
38
47
  rainbow (>= 2.2.2, < 4.0)
39
48
  ruby-progressbar (~> 1.7)
40
- unicode-display_width (~> 1.0, >= 1.0.1)
41
- ruby-progressbar (1.9.0)
42
- unicode-display_width (1.3.0)
43
- yard (0.9.12)
49
+ unicode-display_width (>= 1.4.0, < 1.6)
50
+ ruby-progressbar (1.10.0)
51
+ simplecov (0.16.1)
52
+ docile (~> 1.1)
53
+ json (>= 1.8, < 3)
54
+ simplecov-html (~> 0.10.0)
55
+ simplecov-html (0.10.2)
56
+ systemcall (1.0.2)
57
+ term-ansicolor (1.7.1)
58
+ tins (~> 1.0)
59
+ thor (0.20.3)
60
+ tins (1.21.1)
61
+ unicode-display_width (1.5.0)
62
+ yard (0.9.20)
44
63
 
45
64
  PLATFORMS
46
65
  ruby
47
66
 
48
67
  DEPENDENCIES
49
- bundler (~> 1.14)
50
- rake (~> 10.0)
68
+ bundler (~> 2.0)
69
+ coveralls (~> 0.8)
70
+ rake (~> 13.0)
51
71
  rspec (~> 3.0)
52
- rubocop (~> 0.53)
72
+ rubocop (~> 0.68.0)
53
73
  vnstat-ruby!
54
- yard (~> 0.9.12)
74
+ yard (~> 0.9.20)
55
75
 
56
76
  BUNDLED WITH
57
- 1.16.1
77
+ 2.0.2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # vnstat-ruby
2
2
 
3
3
  [![Build Status](https://travis-ci.org/tlux/vnstat-ruby.svg?branch=master)](https://travis-ci.org/tlux/vnstat-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/tlux/vnstat-ruby/badge.svg?branch=master)](https://coveralls.io/github/tlux/vnstat-ruby?branch=master)
4
5
  [![Gem Version](https://badge.fury.io/rb/vnstat-ruby.svg)](https://badge.fury.io/rb/vnstat-ruby)
5
6
 
6
7
  Vnstat is a tool that tracks the traffic on your network interfaces.
@@ -13,7 +14,7 @@ maintained by Teemu Toivola.
13
14
 
14
15
  ### Prerequisites
15
16
 
16
- * Ruby 2.1.0 or greater
17
+ * Ruby 2.3.0 or greater
17
18
  * Make sure you have `vnstat` CLI installed by running `which vnstat`.
18
19
 
19
20
  On Ubuntu you can get the vnstat package via `apt-get install vnstat`.
@@ -148,7 +149,7 @@ end
148
149
  ```ruby
149
150
  interface.tops.first
150
151
  interface.tops[2]
151
- # => #<Vnstat::Result::Minute time: #<DateTime: 2015-11-05T09:03:42+00:00>>
152
+ # => #<Vnstat::Result::Minute time: 2015-11-05 09:03:42 +0000>
152
153
  ```
153
154
 
154
155
  ```ruby
@@ -172,4 +173,4 @@ interface.tops[1].bytes_received # => 1024000
172
173
 
173
174
  ### Copyright
174
175
 
175
- Copyright (c) 2015-2017 Tobias Casper. See LICENSE.txt for further details.
176
+ Copyright (c) 2015-2020 Tobias Casper. See LICENSE.txt for further details.
@@ -14,7 +14,6 @@ module Vnstat
14
14
  autoload :InterfaceCollection, 'vnstat/interface_collection'
15
15
  autoload :Parser, 'vnstat/parser'
16
16
  autoload :Result, 'vnstat/result'
17
- autoload :SystemCall, 'vnstat/system_call'
18
17
  autoload :Traffic, 'vnstat/traffic'
19
18
  autoload :Utils, 'vnstat/utils'
20
19
 
@@ -59,17 +58,6 @@ module Vnstat
59
58
  InterfaceCollection.open
60
59
  end
61
60
 
62
- ##
63
- # Returns information for the currently installed version of vnstat.
64
- #
65
- # @deprecated Please use {#cli_version} instead.
66
- # @return [String]
67
- def version
68
- warn '[DEPRECATION] `Vnstat.version` is deprecated. Please use ' \
69
- '`Vnstat.cli_version` instead.'
70
- cli_version
71
- end
72
-
73
61
  ##
74
62
  # Returns information for the currently installed version of vnstat.
75
63
  #
@@ -39,6 +39,7 @@ module Vnstat
39
39
  # @raise [ArgumentError] Raised if the specified data was nil.
40
40
  def data=(data)
41
41
  raise ArgumentError, 'No document data specified' if data.nil?
42
+
42
43
  @data = Nokogiri::XML.parse(data.to_s)
43
44
  end
44
45
 
@@ -47,7 +48,10 @@ module Vnstat
47
48
  #
48
49
  # @return [String]
49
50
  def version
50
- data.xpath('vnstat').attr('version').text
51
+ attr = data.xpath('vnstat').attr('version')
52
+ raise 'Unable to determine version' if attr.nil?
53
+
54
+ attr.text
51
55
  end
52
56
 
53
57
  ##
@@ -55,7 +59,10 @@ module Vnstat
55
59
  #
56
60
  # @return [String]
57
61
  def xml_version
58
- data.xpath('vnstat').attr('xmlversion').text
62
+ attr = data.xpath('vnstat').attr('xmlversion')
63
+ raise 'Unable to determine XML version' if attr.nil?
64
+
65
+ attr.text
59
66
  end
60
67
  end
61
68
  end
@@ -35,6 +35,7 @@ module Vnstat
35
35
  # @return [true, false]
36
36
  def ==(other)
37
37
  return false unless other.respond_to?(:id)
38
+
38
39
  id == other.id
39
40
  end
40
41
 
@@ -71,6 +71,7 @@ module Vnstat
71
71
  def create(id)
72
72
  success = Utils.call_executable_returning_status('--create', '-i', id)
73
73
  return nil unless success
74
+
74
75
  reload
75
76
  self[id]
76
77
  end
@@ -97,9 +98,10 @@ module Vnstat
97
98
 
98
99
  def interfaces_hash
99
100
  @interfaces_hash ||= begin
101
+ id_attr = xml_version == '2' ? :name : :id
100
102
  elements = data.xpath('//interface')
101
103
  elements.each_with_object({}) do |node, hash|
102
- id = node[:id]
104
+ id = node[id_attr]
103
105
  hash[id] = Interface.new(id, data)
104
106
  end
105
107
  end
@@ -33,7 +33,7 @@ module Vnstat
33
33
  # Extracts the date and time from the given XML element.
34
34
  #
35
35
  # @param [Nokogiri::XML::Element] element The XML element.
36
- # @return [DateTime]
36
+ # @return [Time]
37
37
  def extract_datetime_from_xml_element(element)
38
38
  date = extract_date_from_xml_element(element)
39
39
  hour = element.xpath('time/hour').text.to_i
@@ -52,6 +52,7 @@ module Vnstat
52
52
  # @return [Integer, nil]
53
53
  def <=>(other)
54
54
  return nil unless other.respond_to?(:bytes_transmitted)
55
+
55
56
  bytes_transmitted <=> other.bytes_transmitted
56
57
  end
57
58
  end
@@ -41,6 +41,7 @@ module Vnstat
41
41
  def <=>(other)
42
42
  return nil unless other.respond_to?(:bytes_transmitted)
43
43
  return nil unless other.respond_to?(:date)
44
+
44
45
  [date, bytes_transmitted] <=> [other.date, other.bytes_transmitted]
45
46
  end
46
47
  end
@@ -49,6 +49,7 @@ module Vnstat
49
49
  def <=>(other)
50
50
  return nil unless other.respond_to?(:bytes_transmitted)
51
51
  return nil unless other.respond_to?(:time)
52
+
52
53
  [time, bytes_transmitted] <=> [other.time, other.bytes_transmitted]
53
54
  end
54
55
 
@@ -43,6 +43,7 @@ module Vnstat
43
43
  def <=>(other)
44
44
  return nil unless other.respond_to?(:bytes_transmitted)
45
45
  return nil if !other.respond_to?(:year) || !other.respond_to?(:month)
46
+
46
47
  [year, month, bytes_transmitted] <=>
47
48
  [other.year, other.month, other.bytes_transmitted]
48
49
  end
@@ -11,6 +11,7 @@ module Vnstat
11
11
  def <=>(other)
12
12
  return nil unless other.respond_to?(:bytes_transmitted)
13
13
  return nil unless other.respond_to?(:time)
14
+
14
15
  [time, bytes_transmitted] <=> [other.time, other.bytes_transmitted]
15
16
  end
16
17
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'systemcall'
4
+
3
5
  module Vnstat
4
6
  ##
5
7
  # A module containing several utility methods.
@@ -9,7 +11,7 @@ module Vnstat
9
11
  ##
10
12
  # Initiates a system call with the given arguments.
11
13
  #
12
- # @param [Array<String>] args The arguments for the system call.
14
+ # @param [Array] args The arguments for the system call.
13
15
  #
14
16
  # @overload system_call(*args)
15
17
  # @return [String] The output of STDOUT or STDERR, depending of the exit
@@ -21,18 +23,19 @@ module Vnstat
21
23
  # @yieldparam [String] error_result The STDERR output.
22
24
  # @return [Object] The value the called block returns.
23
25
  def system_call(*args)
24
- system_call = SystemCall.call(*args)
25
- return system_call.success_result if system_call.success?
26
- return yield(system_call.error_result) if block_given?
27
- system_call.error_result
26
+ result = SystemCall.call(*args)
27
+ return result.success_result if result.success?
28
+ return yield(result.error_result) if block_given?
29
+
30
+ result.error_result
28
31
  end
29
32
 
30
33
  ##
31
34
  # Initiates a system call with the given arguments and returning whether the
32
35
  # command has been executed successfully.
33
36
  #
34
- # @param [Array<String>] args The arguments for the system call.
35
- # @return [true, false] Indicates whether the command has been executed
37
+ # @param [Array] args The arguments for the system call.
38
+ # @return [Boolean] Indicates whether the command has been executed
36
39
  # successfully (true), or not (false).
37
40
  def system_call_returning_status(*args)
38
41
  SystemCall.call(*args).success?
@@ -41,7 +44,7 @@ module Vnstat
41
44
  ##
42
45
  # Calls the vnstat CLI with the given arguments.
43
46
  #
44
- # @param [Array<String>] args The arguments for the system call.
47
+ # @param [Array] args The arguments for the system call.
45
48
  #
46
49
  # @overload call_executable(*args)
47
50
  # @return [String] The output of STDOUT or STDERR, depending of the exit
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vnstat
4
- VERSION = '2.0.0'
4
+ VERSION = '3.0.6'
5
5
  end
@@ -16,28 +16,21 @@ Gem::Specification.new do |spec|
16
16
  spec.homepage = 'https://github.com/tlux/vnstat-ruby'
17
17
  spec.license = 'MIT'
18
18
 
19
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
20
- # 'allowed_push_host' to allow pushing to a single host or delete this section
21
- # to allow pushing to any host.
22
- if spec.respond_to?(:metadata)
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- else
25
- raise 'RubyGems 2.0 or newer is required to protect against ' \
26
- 'public gem pushes.'
27
- end
28
-
29
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
20
  f.match(%r{^(test|spec|features)/})
31
21
  end
32
22
  spec.bindir = 'exe'
33
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
24
  spec.require_paths = ['lib']
25
+ spec.required_ruby_version = '>= 2.3.0'
35
26
 
36
- spec.add_dependency 'nokogiri', '~> 1.8'
27
+ spec.add_dependency 'nokogiri', '~> 1.10', '>= 1.10.4'
28
+ spec.add_dependency 'systemcall', '~> 1.0', '>= 1.0.2'
37
29
 
38
- spec.add_development_dependency 'bundler', '~> 1.14'
39
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'bundler', '~> 2.0'
31
+ spec.add_development_dependency 'coveralls', '~> 0.8'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
40
33
  spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'rubocop', '~> 0.53'
42
- spec.add_development_dependency 'yard', '~> 0.9.12'
34
+ spec.add_development_dependency 'rubocop', '~> 0.68.0'
35
+ spec.add_development_dependency 'yard', '~> 0.9.20'
43
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vnstat-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Casper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-19 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -16,42 +16,82 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '1.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.10.4
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '1.8'
29
+ version: '1.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: systemcall
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.2
27
53
  - !ruby/object:Gem::Dependency
28
54
  name: bundler
29
55
  requirement: !ruby/object:Gem::Requirement
30
56
  requirements:
31
57
  - - "~>"
32
58
  - !ruby/object:Gem::Version
33
- version: '1.14'
59
+ version: '2.0'
34
60
  type: :development
35
61
  prerelease: false
36
62
  version_requirements: !ruby/object:Gem::Requirement
37
63
  requirements:
38
64
  - - "~>"
39
65
  - !ruby/object:Gem::Version
40
- version: '1.14'
66
+ version: '2.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: coveralls
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.8'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.8'
41
81
  - !ruby/object:Gem::Dependency
42
82
  name: rake
43
83
  requirement: !ruby/object:Gem::Requirement
44
84
  requirements:
45
85
  - - "~>"
46
86
  - !ruby/object:Gem::Version
47
- version: '10.0'
87
+ version: '13.0'
48
88
  type: :development
49
89
  prerelease: false
50
90
  version_requirements: !ruby/object:Gem::Requirement
51
91
  requirements:
52
92
  - - "~>"
53
93
  - !ruby/object:Gem::Version
54
- version: '10.0'
94
+ version: '13.0'
55
95
  - !ruby/object:Gem::Dependency
56
96
  name: rspec
57
97
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +112,28 @@ dependencies:
72
112
  requirements:
73
113
  - - "~>"
74
114
  - !ruby/object:Gem::Version
75
- version: '0.53'
115
+ version: 0.68.0
76
116
  type: :development
77
117
  prerelease: false
78
118
  version_requirements: !ruby/object:Gem::Requirement
79
119
  requirements:
80
120
  - - "~>"
81
121
  - !ruby/object:Gem::Version
82
- version: '0.53'
122
+ version: 0.68.0
83
123
  - !ruby/object:Gem::Dependency
84
124
  name: yard
85
125
  requirement: !ruby/object:Gem::Requirement
86
126
  requirements:
87
127
  - - "~>"
88
128
  - !ruby/object:Gem::Version
89
- version: 0.9.12
129
+ version: 0.9.20
90
130
  type: :development
91
131
  prerelease: false
92
132
  version_requirements: !ruby/object:Gem::Requirement
93
133
  requirements:
94
134
  - - "~>"
95
135
  - !ruby/object:Gem::Version
96
- version: 0.9.12
136
+ version: 0.9.20
97
137
  description: Utilizes the the vnstat CLI to track your network traffic.
98
138
  email:
99
139
  - tobias.casper@gmail.com
@@ -101,19 +141,20 @@ executables: []
101
141
  extensions: []
102
142
  extra_rdoc_files: []
103
143
  files:
144
+ - ".coveralls.yml"
104
145
  - ".document"
105
146
  - ".gitignore"
106
147
  - ".rspec"
107
148
  - ".rubocop.yml"
108
149
  - ".ruby-gemset"
109
150
  - ".ruby-version"
151
+ - ".tool-versions"
110
152
  - ".travis.yml"
111
153
  - Gemfile
112
154
  - Gemfile.lock
113
155
  - LICENSE.txt
114
156
  - README.md
115
157
  - Rakefile
116
- - VERSION
117
158
  - lib/vnstat-ruby.rb
118
159
  - lib/vnstat.rb
119
160
  - lib/vnstat/configuration.rb
@@ -131,7 +172,6 @@ files:
131
172
  - lib/vnstat/result/minute.rb
132
173
  - lib/vnstat/result/month.rb
133
174
  - lib/vnstat/result/time_comparable.rb
134
- - lib/vnstat/system_call.rb
135
175
  - lib/vnstat/traffic.rb
136
176
  - lib/vnstat/traffic/base.rb
137
177
  - lib/vnstat/traffic/daily.rb
@@ -144,8 +184,7 @@ files:
144
184
  homepage: https://github.com/tlux/vnstat-ruby
145
185
  licenses:
146
186
  - MIT
147
- metadata:
148
- allowed_push_host: https://rubygems.org
187
+ metadata: {}
149
188
  post_install_message:
150
189
  rdoc_options: []
151
190
  require_paths:
@@ -154,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
193
  requirements:
155
194
  - - ">="
156
195
  - !ruby/object:Gem::Version
157
- version: '0'
196
+ version: 2.3.0
158
197
  required_rubygems_version: !ruby/object:Gem::Requirement
159
198
  requirements:
160
199
  - - ">="
@@ -162,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
201
  version: '0'
163
202
  requirements: []
164
203
  rubyforge_project:
165
- rubygems_version: 2.7.3
204
+ rubygems_version: 2.5.2.3
166
205
  signing_key:
167
206
  specification_version: 4
168
207
  summary: A library to track your network traffic using vnstat.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module Vnstat
6
- ##
7
- # A class responsible for communication with command line interfaces.
8
- #
9
- # @!attribute [r] args
10
- # @return [Array]
11
- # @!attribute [r] success_result
12
- # @return [String, nil] The STDOUT output of the called command.
13
- # @!attribute [r] error_result
14
- # @return [String, nil] The STDERR output of the called command.
15
- # @!attribute [r] exit_status
16
- # @return [Process::Status, nil] The exit status of the called command.
17
- class SystemCall
18
- attr_reader :args, :success_result, :error_result, :exit_status
19
-
20
- ##
21
- # Initializes the {SystemCall}.
22
- #
23
- # @param [Array] args The command line arguments.
24
- def initialize(*args)
25
- @args = args.flatten
26
- end
27
-
28
- ##
29
- # Initializes and calls the {SystemCall}.
30
- #
31
- # @param [Array] args The command line arguments.
32
- # @return [SystemCall]
33
- def self.call(*args)
34
- new(*args).call
35
- end
36
-
37
- ##
38
- # Calls the command.
39
- #
40
- # @return [SystemCall]
41
- def call
42
- Open3.popen3(*args) do |_, stdout, stderr, wait_thr|
43
- @success_result = readlines(stdout)
44
- @error_result = readlines(stderr)
45
- @exit_status = wait_thr.value
46
- end
47
- self
48
- end
49
-
50
- ##
51
- # Determines whether the command has been called.
52
- #
53
- # @return [true, false]
54
- def called?
55
- !exit_status.nil?
56
- end
57
-
58
- ##
59
- # Returns the command result.
60
- #
61
- # @return [String] Returns result from {#success_result} when command exited
62
- # successfully. Otherwise returns result from {#error_result}.
63
- # @raise [RuntimeError] Raises when the command has not yet been called.
64
- def result
65
- success? ? success_result : error_result
66
- end
67
-
68
- ##
69
- # Indicates whether the command has been executed successfully.
70
- #
71
- # @raise [RuntimeError] Raises when the command has not yet been called.
72
- # @return [true, false]
73
- def success?
74
- raise 'Command not invoked' unless called?
75
- exit_status.success?
76
- end
77
-
78
- ##
79
- # Indicates whether the command has not been executed successfully.
80
- #
81
- # @raise [RuntimeError] Raises when the command has not yet been called.
82
- # @return [true, false]
83
- def error?
84
- !success?
85
- end
86
-
87
- private
88
-
89
- def readlines(io)
90
- io.readlines.join.chomp
91
- end
92
- end
93
- end