Skip to content

Commit 271bad5

Browse files
author
Kirill Platonov
committed
fix bug with list
1 parent 7fdf91b commit 271bad5

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
proxy_manager (0.0.7)
4+
proxy_manager (0.0.8)
55
net-ping (~> 1.7, >= 1.7.2)
66

77
GEM

lib/proxy_manager/main.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(proxies, bad_proxies)
1616
@list_file, @bad_list_file = proxies, bad_proxies
1717

1818
load_list_from_file(proxies)
19+
load_bad_list_from_file(bad_proxies)
1920
end
2021
end
2122

@@ -28,12 +29,13 @@ def get(count = 1)
2829
raise 'List is empty' if @list.empty?
2930

3031
items = []
32+
new_list = @list.clone
3133

3234
@list.each_with_index do |proxy, key|
33-
@list.delete_at(key)
35+
new_list.shift
3436

3537
if connectable? proxy
36-
@list << proxy
38+
new_list << proxy
3739

3840
if count == 1
3941
items = proxy
@@ -47,6 +49,8 @@ def get(count = 1)
4749
end
4850
end
4951

52+
@list = new_list
53+
5054
raise 'There are no available proxy' if items.empty?
5155

5256
if @list_file && @bad_list_file
@@ -90,5 +94,14 @@ def load_list_from_file(proxies)
9094
end
9195
end
9296
end
97+
98+
def load_bad_list_from_file(bad_proxies)
99+
File.open(bad_proxies, "r").each do |line|
100+
line = line.chomp.split(':')
101+
if line[0].is_a? String and line[1].is_a? String
102+
@bad_list << [line[0], line[1].to_i]
103+
end
104+
end
105+
end
93106
end
94107
end

proxy_manager.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
33
# Describe your gem and declare its dependencies:
44
Gem::Specification.new do |s|
55
s.name = "proxy_manager"
6-
s.version = '0.0.8'
6+
s.version = '0.0.9'
77
s.authors = ["Kirill Platonov"]
88
s.licenses = ['MIT']
99
s.email = ["[email protected]"]

0 commit comments

Comments
 (0)