zold 0.13.29 → 0.13.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/zold/remotes.rb +23 -3
- data/lib/zold/version.rb +1 -1
- data/test/test_remotes.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee35d396502c3f5d87f9b65debca6c3e7bd498da
|
4
|
+
data.tar.gz: 5958504831a46a0a40d3cae2af06b26cc78e4c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 493b9c89a94e367e2b54fd441d3a7adb54e44db8b8110d7baee8f87cca5aa9027180c7140c331e7d78a195161f86db2ce6728a07a1f5af5dae86de7ada7be66b
|
7
|
+
data.tar.gz: 3dc8aff3511edd018766cc15e936f4c8ba9c416db82c27a031d760411b52a17cdff8cf2549d744230dfb6ba9238f3dad603788a8ad5647141d381ee2a7970c90
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
<img src="http://www.zold.io/logo.svg" width="92px" height="92px"/>
|
2
2
|
|
3
|
+
[![Donate via Zerocracy](https://www.0crat.com/contrib-badge/CAZPZR9FS.svg)](https://www.0crat.com/contrib/CAZPZR9FS)
|
4
|
+
|
3
5
|
[![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
|
4
6
|
[![Managed by Zerocracy](https://www.0crat.com/badge/CAZPZR9FS.svg)](https://www.0crat.com/p/CAZPZR9FS)
|
5
7
|
[![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/zold)](http://www.rultor.com/p/yegor256/zold)
|
data/lib/zold/remotes.rb
CHANGED
@@ -125,11 +125,17 @@ module Zold
|
|
125
125
|
|
126
126
|
def exists?(host, port = Remotes::PORT)
|
127
127
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
128
|
+
raise 'Host can\'t be nil' if host.nil?
|
129
|
+
raise 'Port can\'t be nil' if port.nil?
|
128
130
|
!load.find { |r| r[:host] == host.downcase && r[:port] == port }.nil?
|
129
131
|
end
|
130
132
|
|
131
133
|
def add(host, port = Remotes::PORT)
|
134
|
+
raise 'Host can\'t be nil' if host.nil?
|
135
|
+
raise 'Host can\'t be empty' if host.empty?
|
136
|
+
raise 'Port can\'t be nil' if port.nil?
|
132
137
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
138
|
+
raise 'Port can\'t be zero' if port.zero?
|
133
139
|
raise 'Port can\'t be negative' if port < 0
|
134
140
|
raise 'Port can\'t be over 65536' if port > 0xffff
|
135
141
|
raise "#{host}:#{port} already exists" if exists?(host, port)
|
@@ -141,6 +147,8 @@ module Zold
|
|
141
147
|
|
142
148
|
def remove(host, port = Remotes::PORT)
|
143
149
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
150
|
+
raise 'Host can\'t be nil' if host.nil?
|
151
|
+
raise 'Port can\'t be nil' if port.nil?
|
144
152
|
raise "#{host}:#{port} is absent" unless exists?(host, port)
|
145
153
|
list = load
|
146
154
|
list.reject! { |r| r[:host] == host.downcase && r[:port] == port }
|
@@ -148,6 +156,8 @@ module Zold
|
|
148
156
|
end
|
149
157
|
|
150
158
|
def iterate(log, farm: Farm::Empty.new)
|
159
|
+
raise 'Log can\'t be nil' if log.nil?
|
160
|
+
raise 'Farm can\'t be nil' if farm.nil?
|
151
161
|
best = farm.best[0]
|
152
162
|
require_relative 'score'
|
153
163
|
score = best.nil? ? Score::ZERO : best
|
@@ -165,6 +175,8 @@ module Zold
|
|
165
175
|
end
|
166
176
|
|
167
177
|
def errors(host, port = Remotes::PORT)
|
178
|
+
raise 'Host can\'t be nil' if host.nil?
|
179
|
+
raise 'Port can\'t be nil' if port.nil?
|
168
180
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
169
181
|
list = load
|
170
182
|
raise "#{host}:#{port} is absent among #{list.count} remotes" unless exists?(host, port)
|
@@ -172,6 +184,8 @@ module Zold
|
|
172
184
|
end
|
173
185
|
|
174
186
|
def error(host, port = Remotes::PORT)
|
187
|
+
raise 'Host can\'t be nil' if host.nil?
|
188
|
+
raise 'Port can\'t be nil' if port.nil?
|
175
189
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
176
190
|
list = load
|
177
191
|
raise "#{host}:#{port} is absent among #{list.count} remotes" unless exists?(host, port)
|
@@ -180,6 +194,9 @@ module Zold
|
|
180
194
|
end
|
181
195
|
|
182
196
|
def rescore(host, port, score)
|
197
|
+
raise 'Host can\'t be nil' if host.nil?
|
198
|
+
raise 'Port can\'t be nil' if port.nil?
|
199
|
+
raise 'Score can\'t be nil' if score.nil?
|
183
200
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
184
201
|
raise "#{host}:#{port} is absent" unless exists?(host, port)
|
185
202
|
list = load
|
@@ -190,15 +207,18 @@ module Zold
|
|
190
207
|
private
|
191
208
|
|
192
209
|
def load
|
193
|
-
CSV.read(file).map do |r|
|
210
|
+
raw = CSV.read(file).map do |r|
|
194
211
|
{
|
195
212
|
host: r[0],
|
196
213
|
port: r[1].to_i,
|
197
214
|
score: r[2].to_i,
|
198
|
-
errors: r[3].to_i
|
199
|
-
home: URI("http://#{r[0]}:#{r[1]}/")
|
215
|
+
errors: r[3].to_i
|
200
216
|
}
|
201
217
|
end
|
218
|
+
raw.reject { |r| !r[:host] || r[:port].zero? }.map do |r|
|
219
|
+
r[:home] = URI("http://#{r[0]}:#{r[1]}/")
|
220
|
+
r
|
221
|
+
end
|
202
222
|
end
|
203
223
|
|
204
224
|
def save(list)
|
data/lib/zold/version.rb
CHANGED
data/test/test_remotes.rb
CHANGED
@@ -39,6 +39,22 @@ class TestRemotes < Minitest::Test
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_reads_broken_file
|
43
|
+
Dir.mktmpdir 'test' do |dir|
|
44
|
+
file = File.join(dir, 'remotes')
|
45
|
+
[
|
46
|
+
',0,0,0',
|
47
|
+
'some garbage',
|
48
|
+
'',
|
49
|
+
"\n\n\n\n"
|
50
|
+
].each do |t|
|
51
|
+
File.write(file, t)
|
52
|
+
remotes = Zold::Remotes.new(file)
|
53
|
+
assert(remotes.all.empty?, remotes.all)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
42
58
|
def test_iterates_and_fails
|
43
59
|
Dir.mktmpdir 'test' do |dir|
|
44
60
|
file = File.join(dir, 'remotes')
|