Class: ProxyFetcher::ProxyListValidator
- Inherits:
-
Object
- Object
- ProxyFetcher::ProxyListValidator
- Defined in:
- lib/proxy_fetcher/utils/proxy_list_validator.rb
Overview
This class validates list of proxies. Each proxy is validated using ProxyFetcher::ProxyValidator
.
Instance Attribute Summary collapse
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
-
#valid_proxies ⇒ Object
readonly
Returns the value of attribute valid_proxies.
Instance Method Summary collapse
-
#initialize(*proxies) ⇒ ProxyListValidator
constructor
A new instance of ProxyListValidator.
-
#validate ⇒ Array<ProxyFetcher::Proxy>
Performs validation.
Constructor Details
#initialize(*proxies) ⇒ ProxyListValidator
Returns a new instance of ProxyListValidator.
16 17 18 |
# File 'lib/proxy_fetcher/utils/proxy_list_validator.rb', line 16 def initialize(*proxies) @proxies = proxies.flatten end |
Instance Attribute Details
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
9 10 11 |
# File 'lib/proxy_fetcher/utils/proxy_list_validator.rb', line 9 def proxies @proxies end |
#valid_proxies ⇒ Object (readonly)
Returns the value of attribute valid_proxies.
12 13 14 |
# File 'lib/proxy_fetcher/utils/proxy_list_validator.rb', line 12 def valid_proxies @valid_proxies end |
Instance Method Details
#validate ⇒ Array<ProxyFetcher::Proxy>
Performs validation
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/proxy_fetcher/utils/proxy_list_validator.rb', line 24 def validate target_proxies = @proxies.dup target_proxies_lock = Mutex.new connectable_proxies = [] connectable_proxies_lock = Mutex.new threads = [] ProxyFetcher.config.pool_size.times do threads << Thread.new do loop do proxy = target_proxies_lock.synchronize { target_proxies.shift } break unless proxy if proxy.connectable? connectable_proxies_lock.synchronize { connectable_proxies << proxy } end end end end threads.each(&:join) @valid_proxies = connectable_proxies end |