vnstat-ruby 2.0.0 → 3.0.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
- SHA256:
3
- metadata.gz: 1147fd1dc7aa2c9d3990b48e410a1a2f68e8ecd3e5dfc390116131f703050624
4
- data.tar.gz: 5804a8055fc72e8f5dd9fefe888072524ebd8ee842fa26194b45130106dbc170
2
+ SHA1:
3
+ metadata.gz: b6862e06e3145d26d76461b2bb6df4840ff73d52
4
+ data.tar.gz: d704f075ed406527a5ebb5dad12572422dc7b5a7
5
5
  SHA512:
6
- metadata.gz: 9e2be0b328f5b8df0dea239b8c2554d812afc439c89798844fe80dc2edf4fb5f1841ffd1036c3470763fca10a2cc21d90a816043030e89bd250edf3151f3ccb6
7
- data.tar.gz: b163535f90d28910ec626e7d3e997c426addb363dfa50b242f5d0a384b0e9b92ceeeadc000a3d4a1d3af52934125b0ecaab6b6409b7b088448c0f810713f1861
6
+ metadata.gz: 59e46295ad1b32dbd8862421e484869f508ab67c75f205eb4e5a3f23a9ba534c24e2e431188415d354250f5263a58e3deb18acf5c9b040b48c6a9f9839e6f7f7
7
+ data.tar.gz: 56ad2d5a85a170c35544c83248b1b6a552d04c00544b9806039eb34e96753eebfe2b9b23d10cdd2c1ca9c77bf0e7478833c15ce4f8524f5c95a391b898402e55
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ require: rubocop-performance
2
+
1
3
  AllCops:
2
4
  Include:
3
5
  - '**/*.rb'
@@ -7,11 +9,12 @@ AllCops:
7
9
  - '**/*.jbuilder'
8
10
  - Rakefile
9
11
  - spec/spec_helper.rb
12
+ TargetRubyVersion: '2.3'
10
13
 
11
14
  Metrics/BlockLength:
12
15
  Exclude:
13
16
  - 'spec/**/*.rb'
14
17
 
15
- Style/FileName:
18
+ Naming/FileName:
16
19
  Exclude:
17
- - Gemfile
20
+ - 'lib/vnstat-ruby.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.3.8
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.3.8
data/.travis.yml CHANGED
@@ -1,12 +1,11 @@
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.1
10
9
  script: bundle exec rspec
11
10
  addons:
12
11
  code_climate:
data/Gemfile.lock CHANGED
@@ -1,21 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vnstat-ruby (2.0.0)
5
- nokogiri (~> 1.8)
4
+ vnstat-ruby (3.0.0)
5
+ nokogiri (~> 1.8.5)
6
+ systemcall (~> 1.0.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  ast (2.4.0)
11
12
  diff-lcs (1.2.5)
13
+ jaro_winkler (1.5.2)
12
14
  mini_portile2 (2.3.0)
13
- nokogiri (1.8.2)
15
+ nokogiri (1.8.5)
14
16
  mini_portile2 (~> 2.3.0)
15
- parallel (1.12.1)
16
- parser (2.5.0.4)
17
+ parallel (1.17.0)
18
+ parser (2.6.3.0)
17
19
  ast (~> 2.4.0)
18
- powerpack (0.1.1)
19
20
  rainbow (3.0.0)
20
21
  rake (10.5.0)
21
22
  rspec (3.3.0)
@@ -31,27 +32,31 @@ GEM
31
32
  diff-lcs (>= 1.2.0, < 2.0)
32
33
  rspec-support (~> 3.3.0)
33
34
  rspec-support (3.3.0)
34
- rubocop (0.53.0)
35
+ rubocop (0.68.0)
36
+ jaro_winkler (~> 1.5.1)
35
37
  parallel (~> 1.10)
36
- parser (>= 2.5)
37
- powerpack (~> 0.1)
38
+ parser (>= 2.5, != 2.5.1.1)
38
39
  rainbow (>= 2.2.2, < 4.0)
39
40
  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)
41
+ unicode-display_width (>= 1.4.0, < 1.6)
42
+ rubocop-performance (1.1.0)
43
+ rubocop (>= 0.67.0)
44
+ ruby-progressbar (1.10.0)
45
+ systemcall (1.0.0)
46
+ unicode-display_width (1.5.0)
47
+ yard (0.9.19)
44
48
 
45
49
  PLATFORMS
46
50
  ruby
47
51
 
48
52
  DEPENDENCIES
49
- bundler (~> 1.14)
53
+ bundler (~> 2.0)
50
54
  rake (~> 10.0)
51
55
  rspec (~> 3.0)
52
- rubocop (~> 0.53)
56
+ rubocop (~> 0.68.0)
57
+ rubocop-performance (~> 1.1.0)
53
58
  vnstat-ruby!
54
- yard (~> 0.9.12)
59
+ yard (~> 0.9.19)
55
60
 
56
61
  BUNDLED WITH
57
- 1.16.1
62
+ 2.0.1
data/README.md CHANGED
@@ -13,7 +13,7 @@ maintained by Teemu Toivola.
13
13
 
14
14
  ### Prerequisites
15
15
 
16
- * Ruby 2.1.0 or greater
16
+ * Ruby 2.3.0 or greater
17
17
  * Make sure you have `vnstat` CLI installed by running `which vnstat`.
18
18
 
19
19
  On Ubuntu you can get the vnstat package via `apt-get install vnstat`.
@@ -148,7 +148,7 @@ end
148
148
  ```ruby
149
149
  interface.tops.first
150
150
  interface.tops[2]
151
- # => #<Vnstat::Result::Minute time: #<DateTime: 2015-11-05T09:03:42+00:00>>
151
+ # => #<Vnstat::Result::Minute time: 2015-11-05 09:03:42 +0000>
152
152
  ```
153
153
 
154
154
  ```ruby
data/lib/vnstat.rb CHANGED
@@ -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
 
@@ -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
data/lib/vnstat/result.rb CHANGED
@@ -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
data/lib/vnstat/utils.rb CHANGED
@@ -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.0'
5
5
  end
data/vnstat-ruby.gemspec CHANGED
@@ -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.8.5'
28
+ spec.add_dependency 'systemcall', '~> 1.0.0'
37
29
 
38
- spec.add_development_dependency 'bundler', '~> 1.14'
30
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
31
  spec.add_development_dependency 'rake', '~> 10.0'
40
32
  spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'rubocop', '~> 0.53'
42
- spec.add_development_dependency 'yard', '~> 0.9.12'
33
+ spec.add_development_dependency 'rubocop', '~> 0.68.0'
34
+ spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
35
+ spec.add_development_dependency 'yard', '~> 0.9.19'
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.0
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: 2019-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: 1.8.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: 1.8.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: systemcall
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '1.14'
47
+ version: '2.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '1.14'
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +86,42 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.53'
89
+ version: 0.68.0
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.53'
96
+ version: 0.68.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.0
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: yard
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: 0.9.12
117
+ version: 0.9.19
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: 0.9.12
124
+ version: 0.9.19
97
125
  description: Utilizes the the vnstat CLI to track your network traffic.
98
126
  email:
99
127
  - tobias.casper@gmail.com
@@ -107,13 +135,13 @@ files:
107
135
  - ".rubocop.yml"
108
136
  - ".ruby-gemset"
109
137
  - ".ruby-version"
138
+ - ".tool-versions"
110
139
  - ".travis.yml"
111
140
  - Gemfile
112
141
  - Gemfile.lock
113
142
  - LICENSE.txt
114
143
  - README.md
115
144
  - Rakefile
116
- - VERSION
117
145
  - lib/vnstat-ruby.rb
118
146
  - lib/vnstat.rb
119
147
  - lib/vnstat/configuration.rb
@@ -131,7 +159,6 @@ files:
131
159
  - lib/vnstat/result/minute.rb
132
160
  - lib/vnstat/result/month.rb
133
161
  - lib/vnstat/result/time_comparable.rb
134
- - lib/vnstat/system_call.rb
135
162
  - lib/vnstat/traffic.rb
136
163
  - lib/vnstat/traffic/base.rb
137
164
  - lib/vnstat/traffic/daily.rb
@@ -144,8 +171,7 @@ files:
144
171
  homepage: https://github.com/tlux/vnstat-ruby
145
172
  licenses:
146
173
  - MIT
147
- metadata:
148
- allowed_push_host: https://rubygems.org
174
+ metadata: {}
149
175
  post_install_message:
150
176
  rdoc_options: []
151
177
  require_paths:
@@ -154,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
180
  requirements:
155
181
  - - ">="
156
182
  - !ruby/object:Gem::Version
157
- version: '0'
183
+ version: 2.3.0
158
184
  required_rubygems_version: !ruby/object:Gem::Requirement
159
185
  requirements:
160
186
  - - ">="
@@ -162,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
188
  version: '0'
163
189
  requirements: []
164
190
  rubyforge_project:
165
- rubygems_version: 2.7.3
191
+ rubygems_version: 2.5.2.3
166
192
  signing_key:
167
193
  specification_version: 4
168
194
  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